c

How to determine start of data payload in TCP packet?

Hi, I'm writing program for monitoring FTP traffic using raw sockets. Now, I am able to determine start of data in TCP packet using this code: // char * packet; // struct * iphdr; // struct * tcphdr; // ... // check, whether sniffed ethernet frame contains IP and TCP char * data; data = (packet + sizeof (struct ethhdr) + sizeof (str...

behaviour of escape characters

#include <stdio.h> main() { printf("az\b\b"); printf("s\ni"); } above program when compiled with gcc gives output sz i Can someone help us out to understand the output ...

Sort an array which is partially sorted

I am trying to sort an array which has properties like it increases upto some extent then it starts decreasing, then increases and then decreases and so on. Is there any algorithm which can sort this in less then nlog(n) complexity by making use of it being partially ordered? array example = 14,19,34,56,36,22,20,7,45,56,50,32,31,45.......

What does the following code do?

static void llist_dtor(void *user, void *element) { (void)user; (void)element; /* Do nothing */ } Is it no-operation function? Then why is casting done? Is it ok to pass NULL as one of its parameters? ...

automatically compare two series -Dissimilarity test

I have two series, series1 and series2. My aim is to find how much Series2 is different from Series1,on a bin to bin basis, (each bin represents a particular feature,) automatically/quantitatively. This image can be seen in its original size by clicking here. Series1 is the expected result. Series2 is the test/incoming series. I am pr...

bitblt is not working properly when display mode is 16 bit in windows

I want to copy a image on to another image where the target image contains the source in the center and rest background should be white. Here is my code hBitmap = (HBITMAP)LoadImage(NULL, "logo.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | /*LR_CREATEDIBSECTION | */ LR_DEFAULTSIZE); GetObject( hBitmap, sizeof(BITMAP), &bm...

How to differentiate executable file and autorun file

What is the difference between the executable files of a compiled program and an autorun program? ...

Casting float inf to integer

What do you get in C from casting float +INF,-INF,NAN to integer? Does any standard specifies what should be the output? For example this code: #include <stdio.h> #include <math.h> int main(int argc, char** argv) { float a = INFINITY; float b = -INFINITY; float c = NAN; printf("float %f %f %f\n", a, b, c); printf("int %d %...

C structure pointer dereferencing speed...

Hello. I have a question regarding the speed of pointer dereferencing. I have a structure like so: typedef struct _TD_RECT TD_RECT; struct _TD_RECT { double left; double top; double right; double bottom; }; My question is, which of these would be faster and why? CASE 1: TD_RECT *pRect; ... for(i = 0; i < m; i++) { if(p[...

Linked Lists, Assigning char array [C]

Hi all. I've got the task of making a car rental program, which uses linked lists to control what cars are available for rent, are rented, or are in repair. The 'car' is a structure, and so is the rented list, available list, and repair list. Heres my current issue. If the user wants to make a new car available, we must add it to our l...

Playing Stereo PCM with DirectSound

Hey, I have simple 16-bit PCM player that I made using DirectSound. But when it plays, it seems that it plays only one speaker instead of both. I don't know what code to post exactly, so you'll have to tell me if you need any. I can say that I create the sound buffer using, and lock the stream using: WAVEFORMATEX wfx; ZeroMemory(&wfx...

Pushing a lua table

I have created a lua table in C, but i'm not sure how to push that table onto the top of a stack so I can pass it to a lua function. Does anyone know how to do this? This is my current code: lua_createtable(state, libraries.size(), 0); int table_index = lua_gettop(state); for (int i = 0; i < libraries.size(); i++) { lua_pushstring...

Avoiding column name redundancy accessing SQL databases?

Hello, I'm working on a program using a SQL database (I use SQLite). What my program does is the following: Creates the tables in the database if they don't exist (on startup) Executes SQL queries (SELECT, UPDATE, DELETE) - decided by the user from the interface What I saw doing this is that there is a lot of redundancy. I give the ...

How to open a file with it's relative path in Linux?

I have a program which opens a file by using a relative path (for instance '..'). Now the problem is, when I execute the program from another directory, the relative path is not relative to the program but relative to the working directory. Thus, if I start the program with '/path/to/program/myprog' it fails to find the file. Is there ...

Struct containing pointers to itself

I am writing a LinkedList in C, the below code represent my Node definition. typedef struct { int value; struct Node* next; struct Node* prev; } Node; I understand (or think that I do) that struct Node not the same as typedef struct Node. Granted my code compiles and runs as it's supposed to, however, I get a lot of warnin...

Executing both 'If' as well as 'else' block.

Possible Duplicates: Stupid Question Regarding If-Else's Simultaneous Execution in C++ or C Is it possble to execute both if and else part of an if else control statement ? Hello everyone.. I had a question in an interview like this which i couldn't answer. Consider Following code block. Assume necessary header files. if(...

What is the best way to get right most number in an integer with C?

I'm just mucking around with C as a learner, and wrote this little function... char *getPlaceSuffix(int number) { static char *suffixes[] = {"st", "nd", "rd", "th"}; if (number >= 11 && number <= 13) { return suffixes[3]; } else { while (number > 10) { number -= 10; } if (num...

Why must loop variables be signed in a parallel for?

I'm just learning OpenMP from online tutorials and resources. I want to square a matrix (multiply it with itself) using a parallel for loop. In IBM compiler documentation, I found the requirement that "the iteration variable must be a signed integer." Is this also true in the GCC implementation? Is it specified in the OpenMP standard? If...

Read binary data (from file) into a struct

I'm reading binary data from a file, specifically from a zip file. (To know more about the zip format structure see http://en.wikipedia.org/wiki/ZIP_%28file_format%29) I've created a struct that stores the data: typedef struct { /*Start Size Description ...

Comparison of float and double variables

Possible Duplicates: Difference between float and double strange output in comparision of float with float literal I am using visual C++ 6.0 and in a program I am comparing float and double variables For example for this program #include<stdio.h> int main() { float a = 0.7f; double b = 0.7; printf("%d %d...