c

Best practices for handling variable size arrays in c / c++?

If I have an array of a fixed size depending on how it is defined and used, I typically use one of two ways to reference it. Array type 1: Since it is a fixed size based on a define, I just use that define in all my loops referencing it. #define MAXPLAYERS 4 int playerscores[MAXPLAYERS]; for(i=0;i<MAXPLAYERS;++i) { .... do something ...

Argument-parsing helpers for C/UNIX

I know of the following: the venerable getopt(3) the extended getopt_long glibc's argp parser for unix-style argument vectors popt from the GNOME project (or its spiritual successor in Glib) I'm sure there's more that I haven't used or even heard of; a quick Google search reveals Gopt, argtable, and Optlist. Personally, I like argp ...

Any good online C reference manual?

I've studied C programming in college some years ago and have developed some medium applications back then (nothing serious). Now I have to develop some more 'advanced' C applications (involving POSIX threads and RPC), but right now I'm a little rusty even with the basics. Does anyone know of any good online C reference manual? This may...

Where is the itoa function in Linux ?

itoa() is a really handy function to convert a number to a string. Linux does not seem to have itoa(), is there an equivalent function or do I have to use sprintf(str, "%d", num) ? ...

Can a recursive function be inline?

inline int factorial(int n) { if(!n) return 1; else return n*factorial(n-1); } As I was reading this, found that the above code would lead to "infinite compilation" if not handled by compiler correctly. How does the compiler decide whether to inline a function or not ? ...

How do I use micro-state accounting in Linux?

I would like to access micro-state accounting timers programmatically on Linux. I guess the first part of the question is where are these available? Which kernel versions and distros? Which hardware platforms? The second part is how to actually go about accessing the timers? What is the system call? Here is a (somewhat old) page describ...

Drag and drop in winapi

I have a pure Winapi application that needs a few new features. One of them would best be implemented as two lists where you can drag-and-drop (multiple) elements between the lists. The new feature can be limited to a single dialog. What would be the quickest way to implement this? A few ideas: Pure Winapi (is it DetectDrag) A separat...

Stack memory read

Hi, With the following piece of code: typedef struct { char fileName[ 1024]; time_t deleteTime; } file_item_t; .... .... setEntry(char *fileName) { file_item_t file; memset( &file, 0x00, sizeof( file_item_t )); memcpy( file.fileName, fileName, sizeof( file.fileName ) - 1 ); ... ... ...

Can pipes be used across LAN computers?

Can pipes be used across LAN computers? In particular I'm looking for Windows, but if you have more info on other platforms, that will also help others who find this thread later. ...

Why are pipes considered dangerous to use in Windows/unix/linux?

Why are pipes considered dangerous to use? What can be done to avoid these security issues? I'm mostly interested in Windows, but if you have other OS information, please provide. ...

Storing PCRE compiled regexes in C/C++

Is there an efficient way to store the compiled regexes (compiled via regcomp(), PCRE) in a binary file, so that later I can just read from the file and call regexec()? Or is it just a matter of dumping the compiled regex_t structs to the file and reading them back when needed? ...

What will pNext be in the following case using C/C++?

func() { Object* pNext; func1(pNext); } func1(Object* pNext) { pNext = Segement->GetFirstPara(0); } I was expecting it to be pointer to firstpara returned from func1() but I'm seeing NULL can some explain and how to fix it to actually return the firstpara() pointer? ...

Stop JAVA and C from truncating my floats and doubles!

When I give JAVA and C BIG floats and doubles (in the billion range), they convert it to scientific notation, losing precision in the process. How can I stop this behavior? ...

Progress string parsing in C

I have the following character string: "..1....10..20....30...40....50...80..." and I need to extract all numbers from it into array. What is the best way to do it in C? ...

What's a good C decompiler?

I am searching for a decompiler for a C program. The binary is a 32-bit Linux executable. Objdump works fine, so basically I am searching for something which attempts to reconstruct the C source from the asm source. ...

Are there any good open source BDD tools for C/C++?

I love the Ruby RSpec BDD development style. Are there any good tools for doing this with C/C++? ...

Unmanaged C++ encrypted string into C# byte[]

I have an unmanaged C dll I call from a C# class library that encrypts a string value into an encrypted string that contains non-ascii characters. I need to take the data and write its binary values to a file but C# treats text as strings rather than a byte[]. The encrypted value commonly contains special characters (\r, \O, etc). Whe...

How to release the memory that has been used for a variable in C?

How can i release the memory that I used for a variable (e.g. a long string) in C? ...

Looking for an open source Traveling Salesman function / library in c / c++?

I know there are a few different Traveling Salesman projects out there and I've played with LKH a bit, but I was wondering if anyone had any recommendations on any other ones? My project is GPL'ed so I would need something that is compatible with that license. ...

[C] How can I initialize an array of pointers to structs?

Is it possible to initialize an array of pointers to structs? Something like: struct country_t *countries[] = { {"United States of America", "America"}, {"England", "Europe"}, {"Ethiopia", "Africa"} } I want to do that in order to get the entities in not-contiguous memory, and the pointers to them in contiguous mem...