c

evaluation of operand in sizeof operator

As sizeof operator evaluates operand if it's a VLA so I tried to test it as : #include<stdio.h> int main(void) { int sz=20,i=0,j=0; int arr[sz]; printf("%d\n",sizeof((++i,sz))); printf("%d\n",sizeof((++j,arr))); printf("%d\n%d\n",i,j); } I thought that i won't increment as sz is not VLA but j would increment as arr is VL...

Open directory using C

i am accepting the path through command line input. when i do dir=opendir(args[1]); it doesnt enter the loop...i.e dir==null... how do i pass the commandline input to dir pointer??? void main(int c,char **args) { DIR *dir; struct dirent *dent; char buffer[50]; strcpy(buffer, args[1]); dir = opendir(buffer); //t...

array of pointers to a char array

Hello, gcc 4.4.4 c89 However, I am having a problem trying to display all the animals. I have the following code. I am trying display all the animals in the array. So I have 3 array of pointers to char*. Then an array of pointers to these data sets. I have tried to control the inner loop for checking for a -1 and a NULL for the oute...

how do i compile a C++program to work in the windows operating system using g++ for linux?

I am new to writing programs in c++ and i want to know if there is a way to export it to a windows format. Also what is a good way to learn objective-c, is it very different from c++? Thank you in advance. ...

What's the difference in practice between inline and #define?

As the title says; what's the difference in practice between the inline keyword and the #define preprocessor directive? ...

Game of Life memory optimization

Hi I have written a simple game of life code in that uses 2 arrays, one which maintains current state and another which maintains next state. Can anyone suggest how to optimize this program for memory consumption. Ideally, I would like its space complexity to be less than RC. ...

Objective-C and C

Hi! I try to use the "libmsrp", but when I try to compile the library, I have the following error: $ make so gcc -ggdb -shared -Wl,-soname,libmsrp.so.0 -o libmsrp.so.0.0.2 msrp.o msrp_session.o msrp_message.o msrp_relay.o msrp_switch.o msrp_callback.o msrp_network.o msrp_utils.o -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-...

Compilation problem in tokyo cabinate C program

hello, i am new to tokyo cabinet and i have installed it and i have run the example c program i am getting error... while i compile with gcc gcc -O tcadbex.c /tmp/cc7IEOht.o: In function `main': tcadbex.c:(.text+0xd): undefined reference to `tcadbnew' tcadbex.c:(.text+0x1f): undefined reference to `tcadbopen' tcadbex.c:(.text+0x58):...

wmain vs main C runtime

Hi, I have read few articles about different Windows C entry pooints, wmain and WinMain. So, if I am correct, these are added to C language compilers for Windows OS. But, how are implemented? For example, wmain gets Unicode as argv[], but its Os that sends these arguments to program, so is there any special field in the .exe file entry...

multiple word string input through scanf( )

what was the syntax to input strings with more than one word i.e with space in between through scanf() not gets() ...

Implement Hanning Window

I take blocks of incoming data and pass them through fftw to get some spectral information. Everything seems to be working, however I think I'm getting some aliasing issues. I've been trying to work out how to implement a hann window on my blocks of data. Google has failed me for examples. Any ideas or links I should be looking at? dou...

C :: using sscanf to parse string, caveat: context sensitive :-(

Hello, I've some string (char *) in C and using sscanf to tokenize it. I'm generating C source-code and using sscanf is easiest solution, however there is this problem: There is regular expression for parameter: [$]([a-zA-Z0-9_-]{0,122})?[a-zA-Z0-9] (Starting with $, can contain numbers, letters, '-' and '_', but later two can not b...

Selecting and analysing window of points in an array

Could someone please advise me on how to resolve this problem. I have a function which performs a simple regression analysis on a sets of point contained in an array. I have one array (pval) which contains all the data I want to perform regression analysis on. This is how I want to implement this. I get an average value for the first ...

finding min & max

i wrote the code but i dont get max value how to find max value #include <stdio.h> int main(void) { double temp[0]; float max,min; float i; short c,j,k; float sum=0; float nu[c]; printf("Number of values :"); scanf("%f",&i); for (c=1;i>=c;c++) { ...

Why does printf not print out just one byte when printing hex?

pixel_data is a vector of char. When I do printf(" 0x%1x ", pixel_data[0] ) I'm expecting to see 0xf5. But I get 0xfffffff5 as though I was printing out a 4 byte integer instead of 1 byte. Why is this? I have given printf a char to print out - it's only 1 byte, so why is printf printing 4? NB. the printf implementation is wrapped up...

How to protect init function of a C based library?

I have written a C based library and for it to work in multi-thread parallely, I create some global mutexes in the init function. I expect the init function to be called in the main thread before the library APIs are used in multi-thread. But, if the init function itself is called in multi-thread directly, then it is a problem. Is ther...

Using getrusage

Hello Everyone! As a continuation of this question I'm wondering if I can get some simple sample code as to how to make use of getrusage. I would like to use it to find the time CPU used by a process, ideally from the PID. I'm working in Cocoa, Objective_C and of course C. Any help would be awesome! Thanks ...

Linked Lists: Inserting at the end using last pointer.

I'm learning linked lists, and want to know whether the following program (basically InsertAtEnd function) I've made for inserting elements at the end of the list is correct. The basic idea is that *HEAD points to the first element of the list and *LAST points to the last element. This saves the time and calculations in traversing to th...

IPC bottleneck?

I have two processes, a producer and a consumer. IPC is done with OpenFileMapping/MapViewOfFile on Win32. The producer receives video from another source, which it then passes over to the consumer and synchronization is done through two events. For the producer: Receive frame Copy to shared memory using CopyMemory Trigger DataProduced...

implementation of strstr() function

The code says at many places "invalid indirection".Please help. int main() { char *s1,*s2,*position; printf("Enter string:\n"); gets(s1); printf("Enter word to find:\n"); gets(s2); *position=ststr(*s1,*s1); if(*position) printf("word is found at %c loc\n",*position)...