c

The optimum* way to do a table-lookup-like function in C?

I have to do a table lookup to translate from input A to output A'. I have a function with input A which should return A'. Using databases or flat files are not possible for certain reasons. I have to hardcode the lookup in the program itself. What would be the the most optimum (*space-wise and time-wise separately): Using a hashmap, wi...

How to access image Data from a RGB image (3channel image) in opencv

I am trying to take the imageData of image in this where w= width of image and h = height of image for (int i = x; i < x+h; i++) //height of frame pixels { for (int j = y; j < y+w; j++)//width of frame pixels { int pos = i * w * Channels + j; //channels is 3 as rgb // if any data exists if (data->imageD...

How to define NULL using #define

I want to redefine NULL in my program such as #define MYNULL ((void*)0) But this definition is not working in the following statement: char *ch = MYNULL; Error : can not convert from void* to char * What would be the best way to define NULL? ...

how to change the default exe icon in C/C++?

Hello friends,I want to change the default exe icon to someother icon in c/c++ do anybody know how to do that?Please help guys... ...

Handling SIGCHLD will return EOF to the father, why?

I have a small shell that creates children (with fork()) and make them execute some commands with execvp. It support also the & option so the father can run other commands in the meanwhile. When a child die i want to write that on the console and also the child pid, so i defined a sighandler for SIGCHLD: void backdeadchild(int sig) { i...

Two .c files have identical compilation settings - VC++ reports no error and doesn't compile one of them

I'm trying to compile a set of .c files from an open source project into a static library. I've created a VC++9 project file, set everything up as usual. I add two .c files into the project. They don't have any special compilation settings - all the settings are set at the project level and are set to default except that I turned off the...

Why would someone use C instead of C++?

Possible Duplicate: Why artificially limit your code to C? I started off with learning C, but then jumped straight into C++ simply because it supports OO and was also required for subsequent work. However, some companies insist on employing people with particularly strong C experience - and I've noticed this applies especially...

I'm creating opensource GPL H264 encoding lib/app (based on x264) do I need to pay for the license?

I'm creating opensource GPL H264 encoding lib/app (based on x264) do I need to pay for the license? ...

select()-able timers

select() is a great system call. You can pack any number of file descriptors, socket descriptors, pipes, etc. and get notified in a synchronous fashion when input becomes available. Is there a way to create an interval/oneshot timer and use it with select()? That would save me from having multiple threads for IO and timing. ...

Prepending to a string

What is the most efficient way to prepend to a C string, using as little memory as possible? I am trying to reconstruct the path to a file in a large directory tree. Here's an idea of what I was doing before: char temp[LENGTH], file[LENGTH]; file = some_file_name; while (some_condition) { parent_dir = some_calculation_that_yields...

Cumulative Normal Distribution Function in C/C++

I was wondering if there were statistics functions built into math libraries that are part of the standard C++ libraries like cmath. If not, can you guys recommend a good stats library that would have a cumulative normal distribution function? Thanks in advance. More specifically, I am looking to use/create a cumulative distribution fun...

constant variables not working in header

if I define my constant varibles in my header like this... extern const double PI = 3.1415926535; extern const double PI_under_180 = 180.0f / PI; extern const double PI_over_180 = PI/180.0f; I get the following error 1>MyDirectX.obj : error LNK2005: "double const PI" (?PI@@3NB) already defined in main.obj 1>MyDirectX.obj : error LNK2...

Array of strings in C

I'm trying to create a structure storing strings and I'm getting an error incompatible types when I try and insert as string into the array. This my first time working with a program in C. Could somebody help spot my problem. This is my implementation of list.c struct list *init_list(int num) { struct list *p; p = malloc(LIS...

C libcurl get output into a string

hi there i want to get into a var the result of this curl funcion how can i do? thanks! #include <stdio.h> #include <curl/curl.h> int main(void) { CURL *curl; CURLcode res; curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, "curl.haxx.se"); res = curl_easy_perform(curl); /* always cleanup */ ...

C++ Pointers. How to assign value to a pointer struct?

I have the following struct: typedef struct{ int vin; char* make; char* model; int year; double fee; }car; Then I create a pointer of type car car *tempCar; How do I assign values to the tempCar? I'm having trouble tempCar.vin = 1234; tempCar.make = "GM"; tempCar.year = 1999; ...

how to exit a child process - _exit() vs. exit

Consider this code snippet: pid_t cpid = fork(); if (cpid == -1) { perror("fork"); exit(EXIT_FAILURE); } if (cpid == 0) { // in child execvp(argv[1], argv + 1); perror("execvp); _exit(EXIT_FAILURE); } // in parent How shall I exit the child process if execvp returns? Shall I use exit() or _exit()? ...

Checking for success of fwrite in C, perror

With fwrite returning the number of successful elements written to the file, by saying: if (!(fwrite(...))) { fprintf(stderr, "Failure"); //perror(???) I sometimes see code that says perror here and I don't know //exactly what this does. } Does this check for successful writing to the file? Are there other things to wor...

Error compiling BASIC "libnotify" code...

#include <libnotify/notify.h> #include <glib.h> #include <unistd.h> int main(int argc, char** argv) { if(argc == 3) { NotifyNotification *n; notify_init("Test"); n = notify_notification_new (argv[1],argv[2], NULL, NULL); notify_notification_set_timeout (n, 3000); //3 seconds if (!notify_not...

Dynamic String Input - using scanf()

I am trying to read input using scanf and storing into char * dynamically as specified by GCC manual. But it is giving compile time error. char *string; if (scanf ("%as",&string) != 1){ //some code } else{ printf("%s\n", *string); free(string); //some code } Edit: scanf("%ms") also works.(see answers) ...

Problems with File I/o when porting old 'C' libraries from 32-bit to 64-bit

I have really old 'c' code that uses read to read a binary file. Here is a sample: uint MyReadFunc(int _FileHandle, char *DstBuf, uint BufLen) { return (read( _FileHandle, DstBuf, BufLen)); } For 64bit OS - char * will be 64 bits but the BufLen is only 32 bits and the returned value are only 32 bits. Its not an option to...