c

nonblocking socket recv problem while using it with epoll

hi there. i've got a problem: sometimes (not regularly) recv returns -1 and errno == EAGAIN while using epoll in edge-triggered mode. piece of code: server_sock = startup(&port); if ( (epollfd = epoll_create(4096)) < 0) { perror("epoll_create error"); exit(EXIT_FAILURE); } ev.events = EPOLLIN | EPOLLET; ev.data.fd = server_soc...

Reading correctly from a file

During the course of my program, I pass the output of an execv() to a file, for logging, (using the outCopy() function) and then print it back on screen to simulate stdout output. (using the printFile() function) The 2 functions are: void printFile(char *fileName) { char *fileContent=(char *)malloc(200*sizeof(char)); ...

compressing socket send data

Hi, I'm trying to send a lot of data(basically data records converted to a string) over a socket and its slowing down the performance of the rest of my program. Is it possible to compress the data using gzip etc. and uncompress it at the other end? ...

C Read char as binary

This is actually part of a project I'm working on using an avr. I'm interfacing via twi with a DS1307 real-time clock IC. It reports information back as a series of 8 chars. It returns in the format: // Second : ds1307[0] // Minute : ds1307[1] // Hour : ds1307[2] // Day : ds1307[3] // Date : ds1307[4] // Month : ds1307[5] // Yea...

File IO tricks using c/c++

Hi,Are there some good books or articles about file processing with c/c++, especially when the file is very large, GB or something like that? ...

Deferencing a pointer error

typedef struct car car_t; struct Car { int carID[QUEUE_SIZE]; int f[QUEUE_SIZE]; }; int main (){ int Array[ARRIVAL_QUEUE_SIZE]; car_t *ddd = (car_t*)malloc(sizeof(car_t)); for(int i =0; i<2; i++){ int carid = ((CARID_NUMBER_MIN)+(int)((double)(NUMBER_MAX-NUMBER_MIN+1)*rand()/(RAND_MAX+1.0))); Array[i] = carid; dd...

C program to merge files not finding EOF, stuck in infinite loop!

I'm having some problems trying to run this program I am working on...The requirements say I was not allowed to use a sort function...I had do something myself....etc. Pretty much, the program compiles but hangs after executed...I'm guessing it's stuck in an infinite loop...but I can't seem to find it... :( This program reads to data f...

difference between character devices vs Terminal devices vs Streams

Hello guys, I am unable to figure out the exact difference between character devices vs Terminal devices vs Streams. Any help is very much appreciated. Thanks & Regards, Mousey. ...

Monitoring CPU and memory loads on xenomai

I'm writing a xenomai applications which spawns a few threads: rt_task_spawn(&fcThread, "fcThread", FC_THREAD_STACK, FC_THREAD_PRIO, 0, &run, (void*)(this)) Each thread is very simple and looks like this: while (true) { rt_queue_read(pThis->pMsgQueue, (void*)(&msg), sizeof(mystruct), TM_INFINITE) … } They are simple threads but...

Passing in array to a function.

int main(){ int right[2][3] = { {1,4,6}, {2,7,5} } .... calc(right); } int calc(int ** right){ printf("%i", right[0][0]); } I calc function that calculate some numbers based on a matrix, but I dont' know why i get seg fault when I access the variable right within the calc function. does any body know the s...

How to find out cl.exe's builtuin macros

Does anyone know how could I find out which are cl.exe's builtin/predefined macros? For example for gcc the following command line will list all the compiler's builtin macros gcc -dM -E - </dev/null EDIT: I'm interested in a way similar to gcc's that is "ask the actual compiler". Thanks ...

Is there any possible way to change a memory location to a shared memory in C?

In c you can do shmid = shmget(SHMEM_KEY, sizeof(int*) * n , SHEMEM_MODE | IPC_CREAT); int* shmem = shmat(shmid, NULL, 0); to assign first given free memory space as a shared memory. Is there any way to assigne current memory space as a shared memory? ...

Socket Programming in C - Webserver

Hi, I am a beginner when it comes to Socket Programming. I am currently trying to develop a web server that can service basic GET and POST http requests from a browser. I am using my laptop as the server and the client both. So the idea is that I should be able to type http://127.0.0.1:PORT/ in Firefox and my web server should be able t...

Is this a valid macro in C?

If I use the macro: #define AND in the following way: if(...) { ... } elseANDif(...) { ... } What output does the preprocessor produce? Edit: I intend to use: #define TEST(params) if(...){...}else the ... in if(...) is a complicated expression using params the ... in {...} performs some operations & is independent of param...

How to find out where all a closed source application is writing to?

I have an application (the source for which I don't have), which can be invoked from command line like this $ ./notmyapp I want to know all the locations where the application is writing to. It outputs some files in the directory it is being called from, but I need to make sure that those are the only files that are created. So, I ne...

store object in an array using ansi c?

I make a structure just like struct abc { //any function or variable } obje[20]; now I want that the each object of abc store in array. means that arr[0] contain obj[0] only; can it is possible. if it is possible then some one help me in this matter. ...

not stopping all threads in gdb

GDB normally stops all threads if a breakpoint is reached (or Ctrl+C is pressed in the GDB shell). I'm aware that commands like scheduler-locking and schedule-multiple exists, but I see no possibility to let a defined thread run in the background while another is debugged. ...

C program without main function ?

Hi is there anyway to write a c program without main function.If so,point it out plz! ...

how to make winxp ms-dos virtual machine work like win98 ms-dos especially graphics

Hi, Initially... I started programming in C. that was was 10 years back(college). The IDE i used was Turbo C++ IDE. All my c programs were 16bit. Memory Model : Huge. Graphics : 4bit (16 colors). Graphics Driver: EGAVGA.BGI Resolution: 640x480. OS: MS-DOS 6.0 (under windows98 it is 7.0 - which always gave an accelerated execution of...

How to program in C on Mac Leopard without XCode IDE ?

Hi, I have just come to Mac world from Linux world and I love my way around in Mac environment. I want to write and practice simple C programs in mac and I was searching for the tools I require. Most (All) of the resources in the web ask me to use XCode as IDE to do programming in C on Mac. XCode, for my purpose seems to be an overkill....