c

How do you determine the size of a file in C?

How can I figure out the size of a file, in bytes? #include <stdio.h> unsigned int fsize(char* file){ //what goes here? } ...

Any good book on best practice and guidelines in developing a SDK in C?

Hi, I'm developing a small SDK in C, is there any good book or article on best practice and guidelines in the subject? I mean functions design, source code organization, portability issues etc. ...

Where should a veteran C programmer start in order to master Java ?

Since I'm taking time of from my day job I thought it's time to learn something other than C. Is there a K&R equivalent book ? Or maybe a very good site that helps the beginner ? What would you recommend as the development environment ? What classes should I start with ? ...

How do you pass a function as a parameter in C?

I want to create a function that performs a function passed by parameter on a set of data. How do you pass a function as a parameter in C? ...

any good tool for makefile generation?

Hi. I'm looking for a tool which can generate makefile for a C/C++ project for different compilers (gcc, microsoft vc++, borland etc) and different platforms (Win, Linux, Mac). ...

Reverse "ON" bits in a byte..

I was reading Joel's book where he was suggesting as interview question: Write a program to reverse the "ON" bits in a given byte. I only can think of a solution using C. Asking here so you can show me how to do in a Non C way (if possible) ...

How can I convert a hexadecimal number to base 10 efficiently in C?

In C what is the most efficient way to convert a hexadecimal value to its base 10 value? For example, if I have FFFFFFFE the result would be 4294967294. ...

Send messages to program through command line

I have this program, we'll call it Host. Host does all kinds of good stuff, but it needs to be able to accept input through the command line while it's running. This means it has to somehow send its other process data and then quit. For example, I need to be able to do this: ./Host --blahblah 3 6 3 5 This should somehow end up calling...

Is there a difference between the onexit() and atexit() functions

Is there any difference between int on_exit(void (*function)(int , void *), void *arg); and int atexit(void (*function)(void)); other than the fact that the function used by on_exit gets the exit status? That is, if I don't care about the exit status, is there any reason to use one or the other? Edit: Many of the answers wa...

Passing more parameters in C function pointers

Let's say I'm creating a chess program. I have a function void foreachMove( void (*action)(chess_move*), chess_game* game); which will call the function pointer action on each valid move. This is all well and good, but what if I need to pass more parameters to the action function? For example: chess_move getNextMove(chess_game* game,...

In a C/C++ program how does the system (windows, linux, mac OS X) call the main() function.

I am looking for a more technical explanation then the OS calls the function. Can anyone help me out or point me to a website or book? Thanks. ...

How do you get a directory listing in C?

How do you scan a directory for folders and files in C? It needs to be cross-platform. ...

How to combine several C/C++ libraries into one?

I'm tired of adding ten link libraries into my project, or requiring eight of them to use my own. I'd like to take existing libraries like libpng.a, libz.a, libjpeg.a, and combine them into one single .a library. Is that possible? How about combining .lib libraries? ...

How does one rank an array (sort) by value? *With a twist*

Hi all, I need to take an array and sort it in c/c++, replacing each value with its' "rank", an integer that corresponds to its position after sort. Heres an example: Input: 1,3,4,9,6. Output: 1, 2, 3, 5, 4. So, I need to replace each value with its position relative to all the other values. I hope that makes sense, but its late, so...

How do I access the Ruby AST from C level code?

I understand that the Ruby 1.8 AST is traversed at runtime using a big switch statement, and many things like calling a method in a class or parent module involve the interpreter looking up and down the tree as it goes. Is there a straightforward way of accessing this AST in a Ruby C extension? Does it involve the Ruby extension API, or ...

Strange C++ errors with code that has min()/max() calls.

I'm seeing strange errors when my C++ code has min() or max() calls. I'm using Visual C++ compilers. ...

Increasing camera capture resolution in OpenCV

In my C/C++ program, I'm using OpenCV to capture images from my webcam. The camera (Logitech QuickCam IM) can capture at resolutions 320x240, 640x480 and 1280x960. But, for some strange reason, OpenCV gives me images of resolution 320x240 only. Calls to change the resolution using cvSetCaptureProperty() with other resolution values just ...

How to make Pro*C cope with #warning directives?

When I try to precompile a *.pc file that contains a #warning directive I recieve the following error: PCC-S-02014, Encountered the symbol "warning" when expecting one of the followin g: (bla bla bla). Can I somehow convince Pro*C to ignore the thing if it doesn't know what to do with it? I can't remove the #warning directive as it's u...

How do you create a debug only function that takes a variable argument list? Like printf()

I'd like to make a debug logging function with the same parameters as printf. But one that can be removed by the pre-processor during optimized builds. For example: Debug_Print("Warning: value %d > 3!\n", value); I've looked at variadic macros but those aren't available on all platforms. gcc supports them msvc does not. ...

Optimizing a search algorithm in C

Can the performance of this sequential search algorithm (taken from The Practice of Programming) be improved using any of C's native utilities, e.g. if I set the i variable to be a register variable ? int lookup(char *word, char*array[]) { int i for (i = 0; array[i] != NULL; i++) if (strcmp(word, array[i]) == 0) ...