c

C - How to locate temp files previously created by tmpfile() ?

I'm working on a multi-process program which basically perform fuzzification on each layer of a RVB file. (1 process -> 1 layer). Each child process is delivering a temp file by using the function: tmpfile(). After each child process finishes its job, the main process has to read each temp file created and assemble the data. The problem ...

Is a bit field any more efficient (computationally) than masking bits and extracting the data by hand?

I have a numerous small pieces of data that I want to be able to shove into one larger data type. Let's say that, hypothetically, this is a date and time. The obvious method is via a bit field like this. struct dt { unsigned long minute :6; unsigned long hour :5; unsigned long day :5; unsigned long month :4; unsigned...

buffering when passing input from standard input to a function

I asked about this yesterday, but I'm still having problems. I wrote a program in C which has a function that processes files which can be passed to it by a file pointer. void process_my_file(FILE *fptr, ...) { /* do work */ } I asked how to read input from standard input and pass it to my function, and it was recommended to me th...

How do I make a simple makefile? GCC Unix

Hi have three files. program.c, program.h, and headers.h program.c #includes program.h and headers.h I need to compile this on Linux using gcc compiler. I'm not sure how to do this. Netbeans created one for me, but it's empty. ...

Is there anything wrong with using sizeof(type[1234])?

I've been using it for years, i.e.: text = (char *)malloc( sizeof(char[1234]) ); instead of: text = (char *)malloc( sizeof(char) * 1234 ); People have told me it's dangerous, but none could say why. I checked the C spec and it's legal. Are there any pitfalls here? ...

PHP gzinflate() in C?

Hi guys! I'm trying since several hours to implement the behaviour of PHP gzinflate() in C. In PHP it's just: gzinflate($str); In Python it's: import zlib ... return zlib.decompress( decoded_data , -15) ... But I just don't manage to implement it in C. Can anybody help me with that? I'm really stuck.. I tried to do something with Zlib ...

Capturing Keystrokes in GNU/Linux in C

If I am working in an application and I press key from keyboard, how can I capture that key (or string), including the source application's name, in C, under GNU/LINUX, in userland, without X11 :) Thanks. ...

How can I check that all my init functions have been called?

I am writing a large C program for embedded use. Every module in this program has an init() function (like a constructor) to set up its static variables. The problem is that I have to remember to call all of these init functions from main(). I also have to remember to put them back if I have commented them out for some reason. Is th...

Will "long i = 1;" cause an implicit type conversion in C?

If I write "long i = 1;" instead of "long i = 1l;", will the 1 be recognized as int and then implicitly converted to long? Edit: Thank you all. I see there's no type conversion. Is this also the case with the suffix u (like 10u)? Then what's the use of those l and u? ...

Representing dynamic typing in C.

I'm writing a dynamically-typed language. Currently, my objects are represented in this way: struct Class { struct Class* class; struct Object* (*get)(struct Object*,struct Object*); }; struct Integer { struct Class* class; int value; }; struct Object { struct Class* class; }; struct String { struct Class* class; size_t length; char* c...

passing a block of memory from a function

I'm trying to figure out how to allocate a block of memory in a function and pass back a pointer to that block through one of the arguments. This is a C program. I seem to be having some trouble. Here's the code: void foo(char *ptr) { if (!(ptr = malloc(size))) printf("error"); /* code here */ printf("buffer a...

what's the difference between the printf and vprintf function families, and when should I use one over the other?

I understand that the difference between the printf, fprintf, sprintf etc functions and the vprintf, vfprintf, vsprintf etc functions has to do with how they deal with the function arguments. But how specifically? Is there really any reason to use one over the other? Should I just always use printf as that is a more common thing to see i...

How do I find the MAC address programatically on IRIX?

How do I find the MAC address of a network card on IRIX? I'd rather not shell out to something that displays it and parse the output. I'm coding C. Methods that require root access are acceptable. ...

Memory locations

Can anyone please give a C code to display all the values in a memory location starting from 0 to end? ...

c++ need help on how to use callback functions

The function header is defined below: /** * \fn int fx_add_buddylist(const char* name, EventListener func, void *args) * \brief rename the group. * * \param name The group name which you want to add. * \param func The send sms operate's callback function's address, and the operate result will pass to this function. * \par...

Compiling C code with conflicting types

I'm coding a program that uses ossp-uuid which defines a type called uuid_t. Now, the problem that I have is that this type is already defined in Mac OSX in the file unistd.h. So, the error I get is: /opt/local/include/ossp/uuid.h:94: error: conflicting types for 'uuid_t' /usr/include/unistd.h:133: error: previous declaration of 'uuid_...

C/C++ - Any good web server library?

Are there any open source, fast web server libraries? Thanks. ...

pthread_cond_timedwait() help.

void wait(int timeInMs) { struct timespec timeToWait; timeToWait.tv_sec = 5; timeToWait.tv_nsec = timeInMs*1000; int rt; pthread_mutex_lock(&fakeMutex); rt = pthread_cond_timedwait(&fakeCond, &fakeMutex, &timeToWait); pthread_mutex_unlock(&fakeMutex); } I'm using this code to try to get a thread to wait ar...

How do I find the size of mounted USB flash drive in C?

I have a flash drive device (/dev/sda1) mounted to /mnt on an embedded linux system (kernel 2.6.23). Using C how do I work out the size of the drive? ...

Fastest dithering / halftoning library in C

I'm developing a custom thin-client server that serves rendered webpages to its clients. Server is running on multicore Linux box, with Webkit providing the html rendering engine. The only problem is the fact that clients display is limited with a 4bit (16 colors) grayscale palette. I'm currently using LibGraphicsMagick to dither images...