c

What is an elegant way to bin/map an integer in various categories in C?

Assume we have an integer 'x' and 'n' possible values that 'x' can be mapped/binned to. What is an elegant way in C to have a function that returns the closest 'nth' value to x? Pseudo code example; int x = 40; int res; int bins[] = { 0, 20, 80, 200 }; /* Sorting is guaranteed */ res = int_bin(x, bins); assert(res == 20); /* 40 is clo...

Why doesn't strerror return a const-qualified pointer?

I was just skimming the C99 standard, looking for something that I don't remeber now, when I noticed that the pointer returned from the strerror function (section 7.12.6.2) isn't const-qualified, even though the standard says: The strerror function returns a pointer to the string, the contents of which are locale-specific. The arra...

Globals: Best option when callback function parameters don't provide enough information in C?

Lets take qsort()'s comparison callback function as an example int (*compar)(const void *, const void *) What happens when the result of the comparison function depends on the current value of a variable? It appears my only two options are to use a global var (yuck) or to wrap each element of the unsorted array in a struct that conta...

splitting double into array in c

I'd like the following code to work: double num = 31415; /* num will never have a decimal part */ /* ... code here so that we can now say*/ printf("%d", num_array[0] == 3 && num_array[1] == 1 && num_array[4] == 5); //1 I realize it's trivial to do this with ints (just int i=0; while( num>0 ) numarr[size-++i]=num%10, num/=10; where siz...

Query on activation record in C

Hi All, Below is a code which I am not understand. #include<stdio.h> int main(int argc, char *argv[]) { int num; printf("\n Number: " ); scanf("%d", &num); if (num >= 0) { int abs = num; } else { int abs = -num; } { int abs; prin...

is there a GCC compiler/linker option to change the name of main?

My software has one main for normal use and a different one for unit tests. I would just love it if there was an option to gcc to specify which "main" function to use. ...

find most often seen string from a log file

hello guys, I want to find most often seen string in a huge log file. Can someone help me how to do this. one way to do this is to hash each and every string and count the maximum value but its not efficient. Are there any better ways to do this. Thanks & Regards, Mousey. ...

My app mem usage is growing using pthread.

Hi, I am using C language and Linux as my programming platform. In my user-space application. I used pthread to create a thread. int main() { pthread_t thread1, thread2; pthread_create( &thread1, NULL, fthread1, NULL ); pthread_create( &thread2, NULL, fthread2, NULL ); return 0; } void *fthread1( void *ptr ) { /* do s...

How to deal with duplicated function name within C?

I have a little project in which I named two same name function in two different source file, but while I building the project, the compiler failed with 'func_name already defined in filename.obj'. Why could not I have two function with the same name in two differenct source file? I thought the function should be local to the source fil...

Syntax error before '^' token

I just upgraded core-plot to the latest version in an application that was already running successful plots. I followed the fairly simple instructions to the letter, however I'm getting 20 syntax errors in UIView.h. It seems that I'm not alone, but nobody has of yet posted a solution to the issue. An example: This code from UIView.h +...

pthread_create memory leak

Hi, I am using C language and Linux as my programming platform. In my app, I call pthread_create. Then I check the memory usage of my app using ps commandline tool and it adds 4 in the VSZ column. But the problem is when the pthread_create function handler exits, the 4 that was added in the memory was not release. Then when the app ca...

tiff image code in c language

Can you suggest me a website for reading a tiff image code in c language? ...

Sometimes my windows handle is good, sometimes it bad

I am confused. Sometimes when I initiate my window, the Handle returned is good. and sometimes its not. Here is my code void GXRenderManager::InitWindows() { WNDCLASSEX wndcex; wndcex.cbSize = sizeof(WNDCLASSEX); wndcex.style = CS_HREDRAW | CS_VREDRAW; wndcex.lpfnWndProc = GXRenderManager::WndProc; wndcex.cbCls...

Creating a menu strip with WinAPI

In .Net there is something called a menu strip. These are more customizable than HMENU's. How could I create one of these in unmanaged C++? Thanks ...

failure to create a DirectX device and swapchain

I am having issues retrieving a swapchain and device from directx. further info is in the code void GXDX::StartUp(HWND* mainWindow,int w, int h) { //width and height are members of GXDX width = w; //contains the width height = h; //contains the height this->mainWindow = mainWindow; // Is a handle to the main window. i...

Bitwise setting in C++

#define OUTGOING_MASK 0x0c #define OUTGOING_DISABLED 0x04 #define OUTGOING_ENABLED 0x08 #define OUTGOING_AUTO 0x00 #define REFER_SUPPORTED 0x80 Assume support is some value of type int. I have a getter function int get() { if(OUTGOING_DISABLED == support & OUTGOING_MASK) return 1; else if(OUTGOING_ENABL...

printf behaviour on passing a structure member in C language

Hi All, I was trying a program to understand the behavior of structure variable, Sample code: struct temp { int a; int b; }obj; int main() { obj.a = 10; obj.b = 7; /* to see whether obj and &obj both are same * I was verifying whether structure variables behave as arrays */ printf("%d -- %p",obj,&obj); ...

In SDL, does SDL_Quit() free every surface?

Basically, on surfaces that are going to exist right until the program terminates, do I need to run SDL_FreeSurface() for each of them, or would SDL_Quit() take care of all this for me? I ask mainly because the pointers to a number of my surfaces are class members, and therefore I would need to keep track of each class instance (in a g...

software developing

I'm graduating with a Computer Science degree ,i got job at x software company for last month now they told u do project but i don't know about project so how will i do the project just explain it . ...

Is there anyway to access the general purpose registers of ARM with C?

I have installed linux 2.6. I wanted to know if there are any drivers to access the GPR port pins. ...