c

checking for NULL before calling free

Many C code freeing pointers calls: if (p) free(p); But why? I thought C standard say the free function doesn't do anything given a NULL pointer. So why another explicit check? ...

formatting the output using c

i have multiple outputs that i need to print as columns side by side. is there any way to achieve this using C? something like the output of ls -a i.e. i want to print the first column data, then the second and so on ...

C Function alignment in GCC

I am trying to byte-align a function to 16-byte boundary using the 'aligned(16)' attribute. I did the following: void __attribute__((aligned(16))) function() { } (Source: http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html) But when I compile (gcc foo.c ; no makefiles or linker scripts used), I get the following error: FOO...

Anyone knows of a good addressbook implementation?

I am looking to add an address book to one of my programs. For that purpose, I want to have something that is flexible and customizable to the point of allowing me to hook up additional metadata to contacts in it from third parties. I don't mind paying for a solution as long as I get something that is usable for me. My requirements: ...

Making PNG|jpeg from LaTeX in C or C++

I'm looking for a library (or a cleverer solution) in C or C++ that would make an image file (PNG|jpeg) from LaTeX code. The use of packages is a prerequisite. For now I'm thinking of compiling a .tex file into a .dvi and using dvipng to get a .PNG. There's also the possibility of compiling a .tex file into a .ps file and then convert...

accelerometer use

Hi, I'm relatively new to iphone coding, i am trying to design a simple game whereby i can swing the iphone to trigger the firing of a cannon at the bottom of the screen and hit a moving object. I tried using accelerometer but does not really work out well or maybe have to do with the coding, can someone help me out here? thanks a lot! ...

Getting list of all properties of a node using libxml

Hi, I'm having trouble to find a way to extract a list of all properties of a node without knowing what they're called. I'm extracting single known properties using: xmlGetProp(cur, (const xmlChar*)"nodename") But how to get a list of all properties using libxml2? Regards, marius ...

Why is pointer-to-pointer being used in this prog ?

The following program shows how to build a binary tree in a C program. It uses dynamic memory allocation, pointers and recursion. A binary tree is a very useful data-structure, since it allows efficient insertion, searching and deletion in a sorted list. As such a tree is essentially a recursively defined structure, recursive programming...

Does initialization of 2D array in c program waste of too much time?

I am writing a C program which has to use a 2D array to store previously processed data for later using. The size of this 2D array 33x33; matrix[33][33]. I define it as a global parameter, so it will be initialized for only one time. Dose this definition cost a lot of time when program is running? Because I found my program turn to be ...

Tcp connections hang on CLOSE_WAIT status.

Client close the socket first, when there is not much data from server, tcp connection shutdown is okay like: FIN --> <-- ACK <-- FIN, ACK ACK --> When the server is busying sending data: FIN --> <-- ACK,PSH RST --> And the server connection comes to CLOSE_WAIT state and hang on there for a long time. What's the problem ...

'find' optimization

'find ./ -name *.jpg' I am trying to optimize 'find' command for the above statement. method which handle the '-name' predicate in find implementation. static boolean pred__name __common (const char *pathname, const char *str, int flags) { boolean b; char *base = base_name (pathname); strip__trailing __slashes(base); ...

Speedup writing C programs using a subset of the Python syntax

I am constantly trying to optimize my time. Writing a C code takes a lot of time and requires much more keyboard touches than say writing a Python program. However, in order to speed up the time required to create a C program, one can automatize many things. I'd like to write my programs using smth. like Python but with C semantics. I...

Optimization for division on "extern const int"

Hi, I work in project in which I have the following code: file1.c extern const int z; int x; do_some_stuff_to_calculate_x(); y = x / z; do_some_stuff_with_y(); file2.c const int z = Z_INIT_VALUE; // some value defined in some .h file. The point of interest is the division in file1.c . Since z is extern, so it is not known in comp...

How to make an unboxed array of floats I can get a Ptr to

I am trying to do some work with HopenGL and I need a Ptr that points to a array of floats. From what I have read uarray and storableArray seem to be the way to go, in some combination some way. ...

How to get difference between two days in iPhone

Hi All, I would like to calculate the no of days,hours,minutes between two different dates in iPhone(Objective C). Please provide any code sample to do the same. Thanks Sandeep ...

Converting color value from float 0..1 to byte 0..255

What would be the correct way of converting color value from float to byte? At first I thought b=f*255.0 should do it, but now I'm thinking, that in this case only the exact 1.0 will be converted to 255, but 0.9999 will already be 254 which is probably not what I want... It seems that b=f*256.0 would be better except that it would have ...

Help with a copy between buffers using memcpy C

I need to copy the content of one buffer to another one in blocks of n bytes (n might vary), several times to check the cache performance. I use memcpy, but I'm afraid I'm not getting successful results. The block size is variable from some kbytes to Mbytes. And I have to reserve the maximum block to use (long double). I'm a little los...

Modulo for doubles

I need to work out if a massive integer (I mean 20 digits...) is prime. I'm trying to use the brute-force method, but (of course) I need to use doubles to contain the original number. However, the modulo operator (%) is an integer operator - thus it is useless to me! Any help would be greatly appreciated, tf. ...

mysql aggregate UDF (user defined function) in C

I need to write an aggregate extension function (implemented in C) for mySQL 5.x. I have scoured the documentation (including browsing sql/udf_example.c) but I do not find anything that is brief, to the point and shows me just what I need to do. This is the problem: I have a C struct (Foo) I have a C function that takes an array of t...

multi-thread access MySQL error

I have written a simple multi-threaded C program to access MySQL,it works fine except when i add usleep() or sleep() function in each thread function. i created two pthreads in the main method, int main(){ mysql_library_init(0,NULL,NULL); printf("Hello world!\n"); init_pool(&p,100); pthread_t producer; ...