c

Print large base 256 array in base 10 in c

I have an array of unsigned chars in c I am trying to print in base 10, and I am stuck. I think this will be better explained in code, so, given: unsigned char n[3]; char[0] = 1; char[1] = 2; char[2] = 3; I would like to print 197121. This is trivial with small base 256 arrays. One can simply 1 * 256 ^ 0 + 2 * 256 ^ 1 + 3 * 256 ^ 2. ...

Semaphore Mutex Concurrency Issue in multithreaded C program

How do i design a multithreaded C program to avoid Semaphore Mutex Concurrency ...

Finding very similar program executions.

Hi, I was wondering if its possible / anyone knows any tools out there to compare the execution of two related programs (for example, assignments on a class) to see how similar they are. For example, not to compare the names of functions, but how they use syscalls. One silly case of this would be testing if a C string is printed as (see...

Button background transparency using Win32 and Visual Styles

Edit: If anyone's tried this in win32 before, am I going in the right direction by using DrawThemeBackground()? I'v recently enabled Visual Styles using a manifest for version 6 of ComCtl32.dll. Example of Visual Styles in Win32: Visual Styles The buttons look great, but I can't figure out how to make the background around the buttons...

How to determine the hardware (CPU and RAM) on a machine?

I'm working on a cross platform profiling suite, and would like to add information about the machine's CPU (architecture/clock speed/cores) and RAM(total) to the report of each run. Currently I need to target Windows and Unix, so I need methods to obtain this information from both platforms, any clues? Edit: Thanks for the great answers...

C pointer arithmetic snippet

I have a program that I'm trying to decode. It is translated to C from another language (whose name is not spoken here), and as I want to understand how it works, I am slowly rewriting the code and simplifying it to use all the nice logical constructs C has to offer. The following little bit keeps popping up in my code, with varying val...

Can gcc accurately catch useless conditionals?

Please examine the following code: if (foo->bar == NULL); foo->bar = strdup("Unknown"); I spent the last part of three hours hunting down that leak with Valgrind, feeling very silly when I discovered the bogus ';'. I know that the above code is valid C, however I would love for gcc to be able to tell me if I'm using a conditional ...

Is there any c function to display the directory permissin?

Hi, I am implementing 'ls' command in c without using 'system' function is there any c function to display the directory permission? Thanks. ...

count repeated elements in an array in C.....

count repeated elements in an array..... input is {1,1,1,1,2,2,2,3,3,4} output is : 1=4 2=3 3=2 4=1 please help me to find out this......... ...

Compact C Folding in Vim

Hi, I'm trying to make a simple Vim script that would create very compact top-level folds for c files. Ideally, if it was run on this code: static void funca(...) { ... } /* Example comment */ static void funcb(...) { ... } Then it would create folds which would look like this when closed: +-- x Lines: static void funca(......

Where Do malloc() / free() Store Allocated Sizes and Addresses?

Hi, where do malloc() and free() store the allocated addresses and their sizes (Linux GCC)? I've read that some implementations store them somewhere before the actual allocated memory, but I could not confirm that in my tests. The background, maybe someone has another tip for this: I'm experimenting a little bit with analyzing the heap...

Simple C implementation to track memory malloc/free?

programming language: C platform: ARM Compiler: ADS 1.2 I need to keep track of simple melloc/free calls in my project. I just need to get very basic idea of how much heap memory is required when the program has allocated all its resources. Therefore, I have provided a wrapper for the malloc/free calls. In these wrappers I need to incre...

dynamic structures in static memory?

GIVEN that you have a fixed area of memory already allocated that you would like to use, what C or C++ libraries will allow you to store a dynamic structure (e.g. a hash) in that memory? i.e. the hash library must not contain any calls to malloc or new, but must take a parameter that tells it the location and size of the memory it is pe...

C# equivalent to C union

Duplicate of http://stackoverflow.com/questions/126781/c-union-in-c Is there a C# equivalent to the C union typedef? What is the equivalent of the following in C#? typedef union byte_array { struct{byte byte1; byte byte2; byte byte3; byte byte4;}; struct{int int1; int int2;}; };byte_array ...

Is "boolean short circuiting" dictated by standard or just mostly used as optimization?

EDIT: Found duplicate once I learned the term for this behaviour. Close as duplicate please. Consider this Class* p = NULL; if( p != NULL && p->Method() == OK ){ // stuff } On all compilers I've worked with, this is quite safe. I.e. the first part of the boolean expression will evaluate to false, and the call to Method() will thus...

How to pass an array in by reference to a function in Objective C

Greetings everyone! I have a function that has an array pointer passed it to modify stuff in an array: (void) arrayFunction:(Byte[])targetarray { // do stuff to targetarray } It's an array of type Byte, but I don't think that I've put the right thing in the round brackets. What should it be instead of (Byte[])? There may be several...

Function with variable nr of parameters

considering this function double avg(double v1,double v2,...) { double sum=v1+v2; int counter=2; double temp; va_list pargs; va_start(pargs,v2); while((temp=va_arg(pargs,double))!=0.0) { sum+=temp; counter++; } va_end(pargs); return sum/counter; } This call printf("%lf\n",avg(3.0,4.5,4...

Layout of Pixel-data in Memory?

I'm writing a C++ library for an image format that is based on PNG. One stopping point for me is that I'm unsure as to how I ought to lay out the pixel data in memory; as far as I'm aware, there are two practical approaches: An array of size (width * height); each pixel can be accessed by array[y*width + x]. An array of size (height), ...

How do I create a Win32 DLL without MSVCR90D.dll?

I am trying to recreate an existing C Win32 DLL with a single, simple function. I have managed to do this using VS C++ 2008 Express, and my new DLL works on my Vista dev machine, and on the client's XP machine. However, it doesn't work on other sites. I have checked dependencies and my DLL requires MSVCR90D.dll and KERNEL32.dll, where...

Is there a way to flush a POSIX socket?

Is there a standard call for flushing the transmit side of a POSIX socket all the way through to the remote end or does this need to be implemented as part of the user level protocol? I looked around the usual headers but couldn't find anything. ...