c

Fundamentals of Game Programming in C

During the last 2 months I've been trying to learn the basics of game programming. So I coded a few simple games in Java to learn the fundamentals, such as Tetris, Checkers and Pac-Man. Now I want to learn/improve my skills in C, so I have this idea of writing those games in C to learn more about memory management, no OOP, etc. I have d...

initialize a C string with multiple quoted strings

Hi, I thought a C string can be initialized with one and only one quoted string. I just wonder how is this correct? char const help_message [] = "Usage: %s [options] files ...\n" "\n" "Options include:\n" " --verbose -v Be verbose\n" " --help -h Print this help message\n" " --output -o ...

Insert text in the input file in Lex (with C)

Hey! I'm trying to help a friend in a college assignment, but i kind of forgot a lot of C an Lex. The thing is, we are trying to parse a HTML and a correspondent CSS file and add to a tag it's style. Eg: HTML <body> </body> CSS body{color:black;} modified HTML <body style="color:black;"> </body> All the regex are done and ...

What does each entry in the Jmp_buf structure hold?

I am running ubuntu 9.10 (karmic koala), and I took a look at the jmp_buf structure which is simply an array of 12 ints. When I use setjmp, and pass in a jmp_buf structure -- 4 out of 12 entries are saved off. These 4 entries are the stack pointer, frame pointer, program counter and return address. What are the other 8 entries for? Are t...

How is memory allocated for a static multi-dimensional array?

All, This has been bugging me for a while now. In C\C++( i guess java and .NET as well) we do not have to specify the row index in a multi-dimensional array. So, for example i can declare an array of ints as such: int Array[][100]; I think static arrays in general are represented as contiguous memory on the stack. So, taking a column...

executing gcc from notepad++?

Hello, How would I compile a file through notepad++, is there away i can invoke the compiler (gcc) and pass through the file onto gcc? i have gcc in C:\Program Files\gcc ...

First thread signal is not caught all others caught

Hey all, Quite a specific question, but I was wondering if anyone has had any problems getting the first signal to be caught in a consumer-producer relationship with multiple consumers (HTTP web server) for(i = 0; i < num_threads; i++) { pthread_cond_init(&condVars[i], NULL); if(strcmp(policy,"FIFO") == 0) pthread_create(&threadArr...

scope of local variables of a function in C

I have heard about the following scenario right when I started programming in C. "Trying to access from outside, a functions local variable will result in error (or garbage value). Since the stack gets cleared off when we return from the function" But my below code sample prints a value of 50. I am compiling the code with latest GCC c...

dynamic allocation/deallocation of 2D & 3D arrays

I know about algorithms to allocate/deallocate a 2D array dynamically, however I'm not too sure about the same for 3D arrays. Using this knowledge and a bit of symmetry, I came up with the following code. (I had a hard time visualizing in 3D during coding). Please comment on the correctness and suggest any better alternative (efficien...

Set timeout for winsock recvfrom

I'm trying to set up a blocking socket to timeout after 16 ms of trying to recvfrom() on a port. Platform is Windows. I've looked at tons of examples online and it seems really simple I just can't seem to get it to work. Any help would be appreciated! #include <winsock2.h> #include <string> #pragma comment(lib, "ws2_32.lib") #defin...

simple client and server

can sum guide me to a link or a program for simple client and server c or c++ code to run on linux The requirement is that should be able to send and receive messages..... ...

Reading different data from a textfile delimited with semicolons in C.

How do one read different records of data that are separated with semicolons into an array in C? from textfile: Text One; 12.25; Text Two; 5; Text Three; 1.253 fopen ... for(i = 0; i < nrRecords; i++) { fscanf(myFile, " %[^;];", myRecords[i].firstText); /* Ok first text*/ fscanf(myFile, "%lf", &myRecords[i].myDouble1); /* But goes...

Inversion of Control or Dependency Injection -- anyone doing it in C?

See, for example, here http://stackoverflow.com/questions/139299/difference-between-dependency-injection-di-inversion-of-control-ioc to remind yourself what IoC and DI are. The question and answer here http://stackoverflow.com/questions/820594/is-inversion-of-control-specific-to-oo-languages suggests that it does not require an OO l...

Tokenize from a textfile reading into an array in C

How do you tokenize when you read from a file in C? textfile: PES 2009;Konami;DVD 3;500.25; 6 Assasins Creed;Ubisoft;DVD;598.25; 3 Inferno;EA;DVD 2;650.25; 7 char *tokenPtr; fileT = fopen("DATA2.txt", "r"); /* this will not work */ tokenPtr = strtok(fileT, ";"); while(tokenPtr != NULL ) { printf("%s\n", tokenPtr); tokenPtr ...

Features of C++ that can't be implemented in C?

I have read that C++ is super-set of C and provide a real-time implementation by creating objects. Also C++ is closed to real world as it is enriched with Object Oriented concepts. What all concepts are there in C++ that can not be implemented in C? Some say that we can not over write methods in C then how can we have different flavo...

c++ high precision time measurement in windows

Hi, I'm interested in measuring a specific point in time down to the nanosecond using c++ in windows. Is this possible? If it isn't, is it possible to get the specific time in microseconds at least? Any library should do, unless I suppose it's possible with managed code. thanks ...

Passing pointer argument by reference under C?

#include <stdio.h> #include <stdlib.h> void getstr(char *&retstr) { char *tmp = (char *)malloc(25); strcpy(tmp, "hello,world"); retstr = tmp; } int main(void) { char *retstr; getstr(retstr); printf("%s\n", retstr); return 0; } gcc would not compile this file,but after adding #include <cstring> I could use g++ to compile this...

C/C++ maximum stack size of program

I want to do DFS on a 100 X 100 array. (Say elements of array represents graph nodes) So assuming worst case, depth of recursive function calls can go upto 10000 with each call taking upto say 20 bytes. So is it feasible means is there a possibility of stackoverflow? What is the maximum size of stack in C/C++? Please specify for gc...

Minimum Number of Operations needed.

Hello everyone there... I have a problem, suppose I have a given string: "best", the target string is suppose: "beast". Then I have to determine the number of operations to convert the given string to the target string, however the operations allowed are: 1. add a character to string. 2. delete a character. 3. swap two char positions. (...

How to input realtime data to do realtime process in c/c++

i doint project about process realtime data from cyber glove( Virtual Hand ) . So i need to write some application that get realtime data from glove and feed to some algorithm. i don't know how to deal with process realtime data, anybody hav some resource? ...