c

Setting an address and Initialization of a pointer

first, I'm sorry for my poor English, it's not my first language. It's my first time to study about pointers and I found somthing really weird. The book I'm reading says * marker means a variable that the 'pa' indicates. But when I try and initialize a pointer int a; int *pA =&a; (they used *pA in this case) and then change it, ...

Tools for C code refactoring

What tools are there that supports refactoring C code (renaming variables, extracting methods, finding method references, ...) Preferably for a Linux environment, but Windows tools are ok too. If there's something available for emacs, even better! ...

why fseek or fflush is always required between reading and writing in the read/write "+" modes.

Q: I'm trying to update a file in place, by using fopen mode "r+", reading a certain string, and writing back a modified string, but it's not working. A: Be sure to call fseek before you write, both to seek back to the beginning of the string you're trying to overwrite, and because an fseek or ff...

Lower Bounds For Floating Points

Are there any lower bounds for floating point types in C? Like there are lower bounds for integral types (int being at least 16 bits)? ...

program to find the sum of digits

I can't figure out the problem in this: #include<stdio.h> int main() { int a,b,count ; count =0; printf("enter the value for a "); scanf("%d ",&a); while(a>0) { b=a%10; count=b+count; a=a/10; printf ("hence the simplified result is %d",count); } return 0; } ...

GStreamer gst_element_factory_make fails

I'm trying out a GStreamer test application, but at runtime the following line fails: demuxer = gst_element_factory_make ("oggdemux", "ogg-demuxer"); // returns NULL I am using MacOSX and installed GStreamer, libogg and vorbis-tools through MacPorts. So I don't see why it fails. Any suggestions on how to make it work? EDIT: SOLVED! ...

difference between #if defined(WIN32) and #ifdef(WIN32)

Hello, I am compiling my program that will running on linux gcc 4.4.1 C99. I was just putting my #defines in to separate the code that will be compiled on either windows or linux. However, I god this error. error: macro names must be identifiers. Using this code #ifdef(WIN32) /* Do windows stuff #elif(UNIX) /* Do linux stuff */ #e...

How can one variable-args function call another?

Say you have 2 functions: void func(int x,int y,...) { //do stuff } void func2(int x,...) { func(x,123,...); } How can you make this work, e.g pass the arg-list to the other function? EDIT: this is a duplicate, can someone merge them or whatever? ...

Function to read files one by one in a directory

I am implementing an SMTP-sender in C which is supposed to read a file from a directory whenever it is created, process data and delete the file. How can I implement this polling function which should keep doing this automatically? ...

Very fast memcpy for image processing?

I am doing image processing in C that requires copying large chunks of data around memory - the source and destination never overlap. What is the absolute fastest way to do this on the x86 platform using GCC (where SSE, SSE2 but NOT SSE3 are available)? I expect the solution will either be in assembly or using GCC intrinsics? I found...

How to auto-sync Header in Visual Studio ?

Do you know if there is a build-in feature or free add-in for Microsoft Visual Studio 2008 that easily generates C-Headers and keeps them in sync with their .c counterparts? I have already looked at Visual Assist X, but I'm not really willing to pay money at the moment. ...

longjmp() from signal handler

I'm using the following code to try to read an input from user and timeout and exit if more than 5 seconds pass. This is accomplished through a combination of setjmp/longjmp and the SIGALRM signal. Here's the code: #include <stdio.h> #include <setjmp.h> #include <unistd.h> #include <string.h> #include <sys/signal.h> jmp_buf buffer; /...

Complicated C cast explanation

I'm trying to figure out what the following code in C does? ((void(*)())buf)(); where 'buf' is a char array. ...

scanf() causing infinite loop

I've a small C-program which just reads numbers from stdin, one at each loop cycle. If the user inputs some NaN, an error should be printed to the console and the input prompt should return again. On input of "0", the loop should end and the number of given positive/negative values should be printed to the console. Here's the program: #...

Adding missing NULL checks after malloc with coccinelle

I want to write a semantic patch for coccinelle, so that it will add if (ptr == NULL) ... checks after calls to malloc where they are missing. Let's say I have the following input source code: #include <stdio.h> #include <stdlib.h> #include <string.h> // memory leaks ignored static void OK_simple(void) { char *ptr; ptr = malloc(100...

Why does printf not flush after the call unless a newline is in the format string? (in C)

Why does printf not flush after the call unless a newline is in the format string? (in C) Is this POSIX behavior? How might I have printf immediately flush every time? Thanks, Chenz ...

get the default email from the user on a Linux box

Is there any way to programmatically get the current user's email address? I know the email is usually user@hostname but is there any I can get the email? I know how to get the username and the hostname so I can build it myself, but I want to be sure that I get the email address even when the email is not user@hostname. Code in C is ap...

C memcpy() a function

Hi guys, Is there any method to calculate size of a function? I have a pointer to a function and I have to copy entire function using memcpy. I have to malloc some space and know 3rd parameter of memcpy - size. I know that sizeof(function) doesn't work. Do you have any suggestions? ...

How to statically link libevent with gcc while compiling?

I have used event.h in on of my project but the server it has to run on does not support it. Moreover I can not install it also. Is there a way I can run my project with minimum modifications. It has to be compiled statically linked in but how do I do that? ...

WinSock Client C

I have a client using select() to check if there is anything to be received, else it times out and the user is able to send(). Which works well enough. However, the program locks up waiting for user input, so it cant recv() again until the user has sent something. I am not having much luck with using threads either, as I cannot seem to ...