c

Is select() Ok to implement single socket read/write timeout ?

I have an application processing network communication with blocking calls. Each thread manages a single connection. I've added a timeout on the read and write operation by using select prior to read or write on the socket. Select is known to be inefficient when dealing with large number of sockets. But is it ok, in term of performance ...

c compilation error

These are my errors: error: static declaration of doct follows non-static declaration error: previous declaration of doct was here. And my code is: int doct(int*); /* <- Second error points here */ private int doct(int *a) { static int a=0; /* First error points here */ a++; *a=a; return 0; } Any suggestio...

Using pthread to perform matrix multiplication

I have both matrices containing only ones and each array has 500 rows and columns. So, the resulting matrix should be a matrix of all elements having value 500. But, I am getting res_mat[0][0]=5000. Even other elements are also 5000. Why? #include<stdio.h> #include<pthread.h> #include<unistd.h> #include<stdlib.h> #define ROWS 500 #defi...

How to define initialized C-array in the Pyrex?

I want to define initialized C-array in Pyrex, e.g. equivalent of: unsigned char a[8] = {0,1,2,3,4,5,6,7}; What will be equivalent in Pyrex? Just array is cdef unsigned char a[8] But how can I made it initialized with my values? ...

secure client/server program in C with OpenSSL

Hello, I'm trying to write a secure client/server program in C with OpenSSL. I've found a code sample at http://www.rtfm.com/openssl-examples/ but I get this error: server: SSL read problem client: Certificate doesn't verify I think the problem is with the certificate generation, but I cannot find it. Any idea? Thanks ...

C function changes behaviour depending on whether it has a call to printf in it

I have a function that processes some data and finds the threshold that classifies the data with the lowest error. It looks like this: void find_threshold(FeatureVal* fvals, sampledata* data, unsigned int num_samples, double* thresh, double* err, int* pol) { //code to calculate minThresh, minErr, minPol omitted printf("minThresh...

How can I get the sizes of various types in c?

I'm looking for the following information to be printed out: sizeof(int) = ? sizeof(float) = ? sizeof(double) = ? sizeof(char) = ? sizeof (167) = ? sizeof(3.1415926) = ? sizeof(‘$’) = ? ...

Same memory space being allocated again & again

In each loop iteration, variable j is declared again and again. Then why is its address remaining same? Shouldn't it be given some random address each time? Is this compiler dependent? #include<stdio.h> #include<malloc.h> int main() { int i=3; while (i--) { int j; printf("%p\n", &j); } ...

How to make the first invocation of a macro different from all the next ones ?

Hi, that may be really simple but i'm unable to find a good answer. How can I make a macro representing first a certain value and then a different one ? I know that's nasty but i need it to implicitly declare a variable the first time and then do nothing. This variable is required by other macros that i'm implementing. Should i levera...

Why does this generate a segmentation fault?

#include<stdio.h> void foo(int **arr) { arr[1][1]++; } main() { int arr[20][20]; printf("%d\n",arr[1][1]); foo((int**)arr); printf("%d\n",arr[1][1]); } ...

floor of double(time_t)

I cannot understand why this throws undefined reference to `floor'": double curr_time = (double)time(NULL); return floor(curr_time); Hasn't it been casted to double, which is what floor receives? ...

Random numbers in C

srand(time(NULL)); for(i = 0; i < n; i++){ for(j = 0; j < (n-1); j++){ a[i][j] = rand(); } } I try to generate random numbers, but they are the same... What should i do? Array declaration: int** a; int i; printf("Enter array size: "); scanf("%d", &n); a = (int**)calloc(n, sizeof(...

C/C++ full file path in assert macro

hello, I am wondering if it's possible to display full file path using the assert macro? I cannot specify full file path in compilation command, is there still a way to do it? My debug environment is linux/g++ ...

Ignore carriage returns in scanf before data.... to keep layout of console based graphics with conio.h

I have the misfortune of having use conio.h in vc++ 6 for a college assignment, My problem is that my graphic setup is in the center of the screen... e.g. gotoxy( getcols()/2, getrows()/2); printf("Enter something"); scanf( "%d", &something ); now if someone accidentally hits enter before they enter the "something", then the cur...

iphone - converting float to integer

This is a simple question: Is this a correct way to get an integer part from a float division? int result = myFloat / anInteger; this is working, but I am not sure if it is the best way. thanks for any help. ...

Writing String.trim() in C

Possible Duplicates: Painless way to trim leading/trailing whitespace in C? Trim a string in C Hi guys, I was writing the String trim method in c and this is the code I came up with. I think it does the job of eliminating leading and trailing whitespaces however, I wish the code could be cleaner. Can you suggest improvements...

Convert function to read from string instead of file in C

I've been tasked with updating a function which currently reads in a configuration file from disk and populates a structure: static int LoadFromFile(FILE *Stream, ConfigStructure *cs) { int tempInt; ... if ( fscanf( Stream, "Version: %d\n",&tempInt) != 1 ) { printf("Unable to read version number\n"); return 0; } c...

What does this error mean: `somefile.c:200: error: the frame size of 1032 bytes is larger than 1024 bytes`?

During a make, I'm seeing an error along the lines of: cc1: warnings being treated as errors somefile.c:200: error: the frame size of 1032 bytes is larger than 1024 bytes The line number points to the closing brace of a c function that has a signature like this: void trace(SomeEnum1 p1, SomeEnum2 p2, char* format, ...) { char st...

Sending an int from Java to C using sockets

I was just wondering how to send an int from a Java application to a C application using sockets. I have got different C programs communicating with each other and have got the Java application retrieving data from the C application, but I can't work out sending. The C application is acting as database, the Java application then sends a...

Write a function in c that includes the following sequence of statements [Wont Compile]

There is a question in my programming languages textbook that is as follows: Write a C function that includes the following sequence of statements: x = 21; int x; x = 42; Run the program and explain the results. Rewrite the same code in C++ and Java and compare the results. I have written code, and played with i...