c

Query regarding syntax used in a header file for socket programming

This is the piece of the code I copied from one of the header file for socket programming. /* Structure describing an Internet socket address. */ struct sockaddr_in { __SOCKADDR_COMMON (sin_); in_port_t sin_port; /* Port number. */ struct in_addr sin_addr; /* Internet address. */ /* Pad t...

Is typedef ever required in C?

Typedef is very useful for portable names, tag names (typedef struct foo Foo;) and keeping complicated (function) declarations readable (typedef int (*cmpfunc)(const void *, const void *);). But are there situations in C where a typedef is really truly needed? Where you cannot accomplish the same by simple writing out the derived type. ...

Explanation of piece of code used in header files for socket programming.

Can anybody explain me this piece of code? /* Pad to size of `struct sockaddr'. */ unsigned char sin_zero[sizeof (struct sockaddr) - __SOCKADDR_COMMON_SIZE - sizeof (in_port_t) - sizeof (struct in_addr)]; here sin_zero is a char array but what is remaining part? It ...

How to communicate between a C and a C# application

What would be the best way to communicate between a C and a C# process. I need to send messages containing commands and params and such from the C# process. to the C process. and the C process then has to be able to send reply's. I start the C process in the C# process. What would be the best way to achieve this? I tried using stdin a...

error:declaration terminated incorrectly

#include<stdio.h> #include<conio.h> void insert(int arr[]); # define LEN 10 int count; void main(void) { clrscr(); int arr[]={20,21,22,23,24}; insert(arr); getch(); } void insert(int arr[]) { if(size==count) printf("no space"); return; int index,value; printf("enter index and value"); scanf("%d %d",index,val...

Array Performance very similar to LinkedList - What gives!?

So the title is somewhat misleading... I'll keep this simple: I'm comparing these two data structures: An array, whereby it starts at size 1, and for each subsequent addition, there is a realloc() call to expand the memory, and then append the new (malloced) element to the n-1 position. A linked list, whereby I keep track of the head, ...

unable to find errors

#include<stdio.h> #include<conio.h> # define rows [3] # define cols [3] void input(int arr2d[][cols]); void print (int arr2d[][cols]); void add (int mat1[][cols],int mat2[][cols],int result[][cols]); int result[][cols]; void main(void) { int mat1[rows][cols],mat2[rows][cols],ans[rows][cols]; input(mat1); input(mat2); add(mat1,mat2,ans); ...

Mouse cursor bitmap

Hi, i am trying to get bitmap from mouse cursor, but with next code, i just can't get colors. Please a little help... Thanks in advance :) CURSORINFO cursorInfo = { 0 }; cursorInfo.cbSize = sizeof(cursorInfo); if (GetCursorInfo(&cursorInfo)) { ICONINFO ii = {0}; int p = GetIconInfo(cursorInfo.hCursor, &ii); // get scree...

CPU Cycle count based profiling in C/C++ Linux x86_64

I am using the following code to profile my operations to optimize on cpu cycles taken in my functions. static __inline__ unsigned long GetCC(void) { unsigned a, d; asm volatile("rdtsc" : "=a" (a), "=d" (d)); return ((unsigned long)a) | (((unsigned long)d) << 32); } I don't think it is the best since even two consecutive call...

How to concatenate two wide strings using a macro in C?

I want to concatenate two wide strings using a macro, so I define some macros: #define VERSION_MAJOR 1 #define VERSION_MINOR 1 #define VERSION_BUILD 0 #define VERSION_REVISION 0 #define _STR(s) #s #define STR(s) _STR(s) #define _TOWSTRING(x) L##x #define TOWSTRING(x) _TOWSTRING(x) //http://stackoverflow.com/questions/240353/convert...

Convert axes coordinates to pixel coordinates

I'm looking for an efficient way to convert axes coordinates to pixel coordinates for multiple screen resolutions. For example if had a data set of values for temperature over time, something like: int temps[] = {-8, -5, -4, 0, 1, 0, 3}; int times[] = {0, 12, 16, 30, 42, 50, 57}; What's the most efficient way to transform the dataset...

Finding the squares in a plane given n points.

Given n points in a plane , how many squares can be formed ...?? I tried this by calculating the distances between each 2 points , then sort them , and look for the squares in the points with four or more equal distances after verifying the points and slopes. But this looks like an approach with very high complexity . Any other ideas ...

C Clear Variable

char x [1000]; x = 'hello'; ..... clear contents of x??? What would i use to clear x? I'm not able to re-initialise it, use strcpy(x, '/0') or free(). ...

I need help with a getFileExt() in C

I'm trying to write a get file extension function in C. This is what I have... char *getFileExt(char *filename) { char ext[10]; while (*filename) { filename++; } while (*filename != '.') { *(ext++) = *(--filename); } strrev(*ext); return ext; } I keep gettin...

Odd jQuery problem - Ajax request to a C program not quite working.

I have this basic setup: C program opens a socket on a specific unused port (let's say 1234) and waits, listening specifically for HTTP requests. Webpage on the same machine, written primarily in CGI, uses jQuery to make an AJAX request targeted at localhost:1234. What I'd like is for the C program to see the request, take some data ...

create a simple dll file with JNI

Im trying to create a simple dll file.Im following the tutorial http://java.sun.com/docs/books/jni/html/start.html when i try to compile the c program i get following error : Warning W8057 HelloWorld.c 10: Parameter 'env' is never used in function Java_He lloWorld_print Warning W8057 HelloWorld.c 10: Parameter 'obj' is never used in ...

Incompatible Types in Assignment?

What is wrong with that line I have indicated below? #include <stdio.h> #include<time.h> main () { int myRandom; char* myPointer[20]; char yourName[20]; char yourAge[20]; char myPal[20]; char yourDOB[20]; char yourCartype[20]; char yourFavoritecolor[20]; char myFriend [][150] = {"The car was ...

Use the c preprocessor to increment defines?

I have an application which needs to define indexes in various .h files in a heirarchical manor. There is a large set of common entries in a single file and a number of variant header files that are pulled in to specific projects. In file: "base.h" #define AAA 1 #define BBB 2 #define CCC 3 In many files like: "variant_extend...

write a program like squid by libpcap

hi can we in a network gateway write a program with libpcap to extract destination web address and other info like squid? in c language. is any better way? if yo can give me some example and guide. ...

Integer to string in C without preallocated char array

Please, look at the following code that just convert an unsigned int to a string (there may be some unhandled cases but it's not my question), allocating a char array in the heap and returning it, leaving the user the responsibility to free it after the use. Can you explain me why such function (and others similar) do not exist in C sta...