c

Breaking program into multiple files - getting error "redefinition; different basic types"

Hi ! I want to break my program into multiple files 1. main.c - is the main function 2. definitions.h - contains #define, typedef, function prototypes 3. functions.c - contains function(prototypes in definitions.h) In definitions.h, I have typedef for structure MyStruct, which is used in definitions.h & functions.c I have done the fo...

graph in c , recomend book

Is any method or software to plot or display graph on unix dump terminal even the dump terminal is one color only(green)? For my knowledge, we can use text based character to draw graph but not graphic mode. platform is unix ansi c compiler CAN anyone recomend web page or a book ? ...

Flexible C code formatter software

I'm looking for a very flexible C code formatting solution. Here's the context: I need to convert some external C code to my organization's "coding rules". For example, these rules demand that I put the type of each variable in its name (int_foo, pfloat_bar, etc.). Most of these rules are completely absurd but I don't have a choice. I ...

How malloc works?

Possible Duplicate: How do free and malloc work in C? Consider a scenario where i have to allocate some 20 bytes of memory through malloc. For the function call to malloc() to be successful, should the 20 bytes be available contiguously in memory or can it be scattered? For eg, in the above case, if there are 4 or 5 chunks of ...

use of D.Knuth pseudo-random generator

Hi all, I need to write a physical simulation software, and I need to use the pseudo-random generator written by D.Knuth, cause it best fits my needs. Though I know how to use it within a hard block of code (a mere #include "rng-double.c"), I can't quite understand how to include it in a modular program where it is needed both within t...

UDP Broadcasting for automatic search of servers

I am making a multiplayer networking game. Now to connect to the server, client needs the ip address of the server. So, the way I implement this is as follows. Client Broadcasts its ip address at Broadcast IP and a port say A. Server listens to it over A, and Server creates a new UDP connection with the client behaving as a client say...

Global initialized variables declared as "const" go to text segment, while those declared "Static" go to data segment. Why?

#include <stdio.h> const int str[1000] = {0}; int main(void) { printf("arr is %d\n", str[0]); return 0; } Has the following output: [-exercises/adam/stack2]:size a.out text data bss dec hex filename 5133 272 24 5429 1535 a.out Whereas: #include <stdio.h> static int str[1000] = {0}; in...

Bitmap in C, binary operations

Hi I am about to create a bitmap that holds control of 512 bits, all 512 bits should be 0 to indicate that the bit is free when the program starts. Function occupyDataBlocks(int number) should find free bits put the position of the bit in the array int data_blocks[] and set the occupied bit to 1. Under is some code that does some of t...

What is required to make a UDP Broadcast in C?

I'm working on broadcast, and I'm failing pretty badly at even getting the thing to work. I know I have to do the setsockopt() call, but what is needed before that to ensure that the broadcast will go to every box on the network? I vaguely remember something about complementing the network address or something like that. I appreciate the...

DDK "Hello World"

How does one begin writing drivers for Windows? Is there some sort of official DDK "Hello World" example out there? While I'm sure it will be way above my head at first, eventually I would like to create a simple MIDI driver, much like the Maple Virtual MIDI Cable where the MIDI messages come from a user application rather than a physi...

pthread_create from a child process

I'm sure I'm missing something basic, but I'm writing a program that fork()s several child processes, each of which create several pthreads. It seems that the pthread_create call never works from a child process. Here is sample code to explain what I mean: #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <pthread.h> ...

versatile pthread based multithread utility library

Hi folks. I don't want to reinvent the wheel, and what I'm looking for most likely already exist in the FOSS world. I'm looking for a pthread bases utility library that implements often used primitives to do communication between threads. My main need is some kind of blocking queue for fixed size messages and the ability to wait for ...

C "Static" Optimization

Hello. I'm reading the book about optimization teckniks. There is not much description or advices in example though. Here's the thing: int agag(int a) { static int dfdfdf = 0; static int prev_resilt = 0; if (dfdfdf == a) return prev_result; dfdfdf = a; a = SomeCalcs(); prev_result = a; return a; } The key thing is: i...

Why can't a function have a reference argument in C?

For example: void foo( int& i ); is not allowed. Is there a reason for this, or was it just not part of the specification? It is my understanding that references are generally implemented as pointers. In C++, is there any functional difference (not syntactic/semantic) between void foo( int* i ) and void foo( int& i )? ...

C Program - Build an index file from another file

I have a .bin file that contains records in CSV format what I want to do is assign each record in the bin file a sequence number. So the first record in the bin file would be assigned 0 and so on. These will be placed into a bianry index file such as (username, seq #). If I have the bin file already created with records in it, how d...

sizeof: Operator or Function?

Possible Duplicate: Why is sizeof an operator? Why is sizeof supposed to be an operator in C, & not a function? Its usage seems similar to that of a function call, as in sizeof(int). Is it supposed to be some kind of a pseudo-function? ...

Problem with Debugging in Eclipse CDT

I'm trying to debug the simple Hello World program that ships with Eclipse CDT. Running the program normally works fine, but when its run through debug mode, puts() doesn't print anything to the console. I tried running the same program with gdb directly and it works fine, printing "!!!Hello World!!!" as expected. Why doesn't puts() pr...

C: Diagramming A Large Library

Is there any tools to assist in diagramming a large C library? I am working on a project to port an existing C library to C++. The C library is largely undocumented with no diagrams. I would like to use a CASE tool to help me understand how the various files interact. There is extern variables in most of the files. If possible I would p...

msvc + GNU make

I understand that the fastest and the most lightweight binary at windows generate only msvc compiler Express edition of msvc is free http://www.microsoft.com/express/windows/ but how to use cl.exe instead of g++.exe? is it possible in common by using GNU make variables produce makefiles which will works with cl.exe and g++? for examp...

How can we find highest and lowest address of heap

Can anyone suggest, how can we find highest and lowest address of heap using C? ...