c

Bit-fields of type other than int?

I have a code which uses bit-fields declared as follows typedef struct my{ const char *name; uint8_t is_alpha : 1; uint8_t is_hwaccel : 1; uint8_t x_chroma_shift; uint8_t y_chroma_shift; } mystr; uint8_t is typedef'ed to unsigned char. Building the code in MS-VS 2008 using this bit fields gives a warning a...

Question about C integral promotion rules.

I have a query about data type promotion rules in C language standard. The C99 says that: C integer promotions also require that "if an int can represent all values of the original type, the value is converted to an int; otherwise, it is converted to an unsigned int." My questions is in case of a C language expression where unsigned in...

how can i check file write permissions in C++ code?

In my C++ program, I want to make sure i can write info to a file. How can I perform this check? ...

Get the process handle of a process by image name

I need the simplest way from C using Win32 to get the process handle of another process by its executable file name. The process I am looking for does not have any registered window classes. I also know that if it is running there will be only one instance of it running. ...

Read and parse line in C/C++; put tokens in an array or vector or similar structure

Hello everyone, I have to submit code to one of the problems in ACM IPC and, as you may know, the time counts a lot. So, I have to read efficiently an input like this: The first line will contain the sequence of integer values associated and the second line will contain the sequence of integer values associated with another sequence. E...

How to hide command prompt for my Windows Gtk Apps?

I am compiling Gtk applications in Windows with MinGW toolchain, but when I run my apps, a command prompt window appears. How can I make this prompt disappear? ...

Multithreaded C program; how to kill processes spawned by threads?

Situation: I am writing a program in C that maintains a number of threads. Once a thread ends, a new one is created. Each thread forks - the child runs a process via exec() and the parent waits for it to finish. In addition, there is a signal handler thread that waits for signals. If SIGINT is detected then it tells the main threa...

Automatically adding Enter/Exit Function Logs to a Project

I have a 3rd party source code that I have to investigate. I want to see in what order the functions are called but I don't want to waste my time typing: printf("Entered into %s", __FUNCTION__) and printf("Exited from %s", __FUNCTION__) for each function, nor do I want to touch any source file. Do you have any suggestions? Is ther...

rcross-platform defining #define for macros __FUNCTION__ and __func__

Hello, Compiling with gcc 4.4.2 and WinXP Visual Studio C++ 2008 #if defined ( WIN32 ) #define __FUNCTION__ __func__ #endif As I want to use the macro to display the function name. I have done the above so I can cross-platform, and use the same func when compiling on linux or windows. However, when I am compiling on WinXP I get the...

C Strange behaviour on 64-bit server

Hi, I have this strange behaviour in Apache post_config handler : int setup_module(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp,server_rec *s) { //1 my_config_t *config = ap_get_module_config(s->module_config, &my_module); //2 log_me(config->logfp, apr_psprintf(ptemp, "My module version %s\n", MY_VERSION)); ...

Interesting Problem (Currency arbitrage)

Arbitrage is the process of using discrepancies in currency exchange values to earn profit. Consider a person who starts with some amount of currency X, goes through a series of exchanges and finally ends up with more amount of X(than he initially had). Given n currencies and a table (nxn) of exchange rates, devise an algorithm that a pe...

Remove redundant whitespace from string (in-place)

Ok so i posted earlier about trying to (without any prebuilt functions) remove additional spaces so "this is <insert many spaces!> a test" would return "this is a test" http://stackoverflow.com/questions/2279679/logic-issues-help-needed As it was homework i asked for no full solutions and some kind people provided me with the fol...

How to insert colored text int a ListView?

Hi! I have a listview with 3 coloumns. The first two columns has values and the third one is empty yet. I want to know, how can i insert a colored text later into the third column? I don't want to color the full row, only the third column with changing colors. Thanks in advance! kampi ...

The Design and Evolution of C

Hi guys, Is there a book that describes the design and evolution of C similiar to the book 'The Design and Evolution of C++' by Bjarne Stroustrup ? thanks, Prakash ...

How to pass in a null character in a command line argument in C?

I would still like to know how to pass in a null character as a command line argument, maybe so that a single string can be passed in as an argument in the form: "to\0be\0or\0not\0to\0be\0" And then parse it. However the program would treat this string as: "to\\0be\\0or\\0not\\0to\\0be\\0" How can I work around this? Is ther...

Get IP address of an interface on linux

How can I get the IPv4 address of an interface in linux from C code ? e.g. I'd like to get the IP address(if any) assigned to eth0 ...

How does the COMSPEC environmental variable effect a cgi executable?

It appears that a cgi app (in C, VS C++) does not inherit the COMSPEC environmental variable. When adding the variable to the application: _putenv( "COMSPEC=C:\\WINDOWS\\system32\\cmd.exe" ); // C4996 the cgi application no longer executes from the browser but is interpreted as a file for download. (i.e. - Save this file?) My quest...

Best approach to writing oo Lua interfaces in c?

Consider the following example (a simple 2d vector lib). Here there is a single constructor function which returns an object table with methods. My issue with this approach is that it is creating new tables with every constructor. Is there a way to use a single instance of the table but change only the _data field which identifies the...

Get a list of the available drives and their sizes

I know you can use a combination of GetLogicalDrives() and GetDiskFreeSpaceEx() to get the list of drives and their sizes. I've been using GetDiskFreeSpaceEx() with no problem but when I try to use GetLogicalDrives() I ran into a problem: I don't want to have to check each possible letter to see whether it exists or not before passing it...

Is this valid standard c?

I am reviewing some optimisation libraries and came across the function signature double solvopt(unsigned short n, double x[], double fun(), void grad(), double options[], double func(), void gradc() ) note that fun() and gard() are passed as function. My q...