c

Fibonacci in C works great with 1 - 18 but 19 does nothing at all...

Yeah right... we are forced to programm some good old C at our university... ;) So here's my problem: We got the assignment to program a little program that show a fibonacci sequence from 1 to n 1 to 18 works great. But from 19 the program does nothing at all and just exit as it's done. I can not find the error... so please give me a hi...

Is there an elegant, industry standard way of implementing substr in C?

Is there an elegant, cross-platform, industry standard way of implementing substr() in C? or is it a case of every developer reinventing the wheel? EDIT: Added 'cross-platform'. ...

How to avoid zombie processes after executing them in background

Hi! we are programming a bash like shell in C but we have problems with the background processes. The thing is that the father waits for the children process when there is no &, we have made a signal_handler for SIGCHLD which have a wait inside. The main problem that we want to avoid is: the signal_handler executes always (with backgro...

Linux: Can Recvmsg be used to receive the IP_TOS of every incoming packet

Can one use recvmsg() to obtain the IP_TOS field of every incoming packet or does it just show the IP_TOS value that is set for the particular socket. If not, does anyone know of a solution to obtain the IP_TOS values of every incoming packets. I am using a UDP application and therefore do not get to view the IP_TOS field at the applicat...

How can I avoid encoding mixups of strings in a C/C++ API?

I'm working on implementing different APIs in C and C++ and wondered what techniques are available for avoiding that clients get the encoding wrong when receiving strings from the framework or passing them back. For instance, imagine a simple plugin API in C++ which customers can implement to influence translations. It might feature a fu...

How to extract semi-precise frequencies from a WAV file using Fourier Transforms

Let us say that I have a WAV file. In this file, is a series of sine tones at precise 1 second intervals. I want to use the FFTW library to extract these tones in sequence. Is this particularly hard to do? How would I go about this? Also, what is the best way to write tones of this kind into a WAV file? I assume I would only need a simp...

I cannot understand the point of this simple code.

I am doing this assignment, and there are some stuff (from start-up materials) that I cannot comprehend. typedef enum { NORTH, EAST, SOUTH, WEST, NUM_POINTS } Point; typedef Point Course[NUM_POINTS] ; I don't get the idea behind the last line , and how can I use it in the code? ...

Strange results while measuring delta time on Linux

Update: fixed delta calculations in code, still the issue remains Folks, could you please explain why I'm getting very strange results from time to time using the the following code: #include <unistd.h> #include <sys/time.h> #include <stdio.h> int main() { struct timeval start, end; long mtime1, mtime2, diff; while(1) { g...

set integer value as bit mask

What is simplest way to assign a bit mask to integer value? For example I want integer with first, third and forth bits = 1, other = 0. Certainly I am looking for code, not for single value! And certainly there lot of possibilities, but I try to find simplest and most descriptive looking ...

Why does this Quicksort work?

I find this Quicksort partitioning approach confusing and wrong, yet it seems to work. I am referring to this pseudocode. Note: they also have a C implementation at the end of the article, but it's very different from their pseudocode, so I don't care about that. I have also written it in C like this, trying to stay true to the pseudoco...

Can knowing C actually hurt the code you write in higher level languages?

The question seems settled, beaten to death even. Smart people have said smart things on the subject. To be a really good programmer, you need to know C. Or do you? I was enlightened twice this week. The first one made me realize that my assumptions don't go further than my knowledge behind them, and given the complexity of software ru...

C function only called once and cyclomatic complexity

Hi! I think this question is more about style: I have an algorithm that has a very high CC (and a lot of lines!). I want to reduce it, and it's easy since there are pieces of code that can be grouped. The problem is that doing things this way I would have a "big" function calling "small" functions which are only called once. In my opin...

Plugin architecture in C using libdl

I've been toying around, writing a small IRC framework in C that I'm now going to expand with some core functionality - but beyond that, I'd like it to be extensible with plugins! Up until now, whenever I wrote something IRC related (and I wrote a lot, in about 6 different languages now... I'm on fire!) and actually went ahead to implem...

Calling a method named "string" at runtime in Java and C

How can we call a method which name is string at runtime. Can anyone show me how to do that in Java and C. Thanks for replying. ...

libarchive reads too many chars when extracting a file

I've written a C program to extract files from a tar archive using libarchive. I'd like to extract a file from this archive and print it to standard output. But I get extra characters. It's garbage, but it's from another file (possibly adjacent to it in the archive.) I expect output to end at </html>. Here is the code that reads t...

Canceling a WSK I/O operation when driver is unloading

I've been learning how to write drivers with the Windows DDK recently. After creating a few test drivers experimenting with system threads and synchronization, I decided to step it up a notch and write a driver that actually does something, albeit something useless. Currently, my driver connects to my other computer using Winsock Kernel ...

When compiling,I write " gcc -g -Wall dene2 dene2.c", then gcc emits some trace

When I compile my code,I write gcc -g -Wall dene2 dene2.c in the console. Then gcc emits some text on the screen. I don't understand what this output means (I couldn't think of a meaningful title for that reason, sorry). I have tried Google searching but haven't had any luck. I'm not asking for a detailed examination of all of the outp...

P/Invoke a Function Passed a StringBuilder

in a C# file i have a class Archiver { [DllImport("Archiver.dll")] public static extern void archive(string data, StringBuilder response); } string data is an input, and StringBuilder response is where the function writes something the archive function prototype (written in C) looks like this: void archive(char * dataChr, ch...

zeroing out memory

Hello, gcc 4.4.4 c89 I am just wondering what most c programmers do when they want to zero out memory. For example I have a buffer of 1024 bytes. Sometimes I do this: char buffer[1024] = {0}; Which will zero all bytes. However, should I declare like this and use memset? char buffer[1024]; . . memset(buffer, 0, sizeof(buffer); I...

Is there a good way to remove a character from a string without copying all the characters following it?

// The first example: char text[] = "henri"; char *p; p = text; *(p + 1) = 'E'; // Output = hEnri // Now If we want to remove the "e" ie hnri, we would go for????? *(p + 1)=????? The obvious answer is to copy the rest of the array "back" one position. But this seems... unpleasant. Surely there is some better way? ...