c

How to pass a struct to a function in a yacc file?

I have this in my yacc file. var_declaration : type_specifier ID ';' {$2->args = ""; $2->value = 0; $2->arraysize = 0; $2->type = "variable";} Everything above works. I want to add this to it. fn($2); From inside the function, I want to do stuff like this. fn(struct symtab sp) { sp->value = 0; } But when I try to c...

Algorithm to find the duplicate numbers in an array ---Fastest Way

Hi, I need the fastest and simple algorithm which finds the duplicate numbers in an array, also should be able to know the number of duplicates. Eg: if the array is {2,3,4,5,2,4,6,2,4,7,3,8,2} I should be able to know that there are four 2's, two 3's and three 4's. Thanks in advance. ...

How to compute the output ?

How to compute the output for the recursive functions ? I know recursion invokes a stack, but am confusing while solving some aptitude question. Given the following code snippet: #include <stdio.h> void fun(int a){ if(a>0){ fun(--a); printf("%d ",a); fun(--a); printf("%d ",a); } return; } int main(void){ int num = 5; fun...

Introduction to GUI programming with c

Hello there, I'm new GUI and programming as whole and so far I have a general understanding of c and have spent quite some time writing console applications. I'm trying to learn GUI but have so far been unsuccessful. I've tried learning wxwidgets (through official documentation), gtk (through official documentation) and win32 (forgers...

Mailslot with string

Hi, I need to make a message concating various parts. So I used ostringstream. Now I have a std::string or a const * char to send by mailslot. I have tryed many ways to do it but every time I receive wrong messages. I would like to know a solution to send messages by mailslot and receive it and show it by console. My code to generate an...

short type variable automatically extended to integer type?

I wanna print the value of b[FFFC] like below, short var = 0xFFFC; printf("%d\n", b[var]); But it actually print the value of b[FFFF FFFC]. Why does it happen ? My computer is operated by Windows XP in 32-bit architecture. ...

What causes the "left but not entered" GCC compiler error?

We recently ran into the following compiler error that repeated at different locations throughout our build: line-map.c: file "<a source_file name>" left but not entered The source file was different at different points in the build. After some time, the compiler finally threw the following error: <header file>: In function `<functi...

Read data into a float array in C

i am making a program where i need to load some floating point data of the format from a file 103.45 123.45 456.67 ...... i was wondering how to store these data directly into a array of floating point numbers using fread(). i guess it is not that hard using pointers but i am not so good with them. can anyone tell me how ...

Why create a .a file from .o for static linking?

Consider this code: one.c: #include <stdio.h> int one() { printf("one!\n"); return 1; } two.c: #include <stdio.h> int two() { printf("two!\n"); return 2; } prog.c #include <stdio.h> int one(); int two(); int main(int argc, char *argv[]) { one(); two(); return 0; } I want to link these programs togethe...

Detecting attached USB devices under Mac OSX

Hello, First of all a statement: I'm a newbie when it comes to programming for the Mac. However I have an assignment which requires USB communication with a device so I thought I'll start with something basic. I took the code from here, built it and ran it from the Terminal. It starts up and writes: Looking for devices matching vendor...

appending in C failing, simply overwriting

Instead of appending "abc" (and thus eventually getting a file full of abcabcabc....), no matter how many times I run this, myfile only containst "abc".... how can I append? #include <stdio.h> #include <string.h> int main(){ char strng[10]; strcpy(strng,"abc"); FILE *my_file; my_file = fopen("myfile","a+"); if (my_f...

10 character id that's globally and locally unique

Hi there! I need to generate a 10 character unique id (SIP/VOIP folks need to know that it's for a param icid-value in the P-Charging-Vector header). Each character shall be one of the 26 ASCII letters (case sensitive), one of the 10 ASCII digits, or the hyphen-minus. It MUST be 'globally unique (outside of the machine generating the i...

Copying a 2D array of char * to user space from kernel space?

In kernel space, I have the following: char * myData[MAX_BUF_SIZE][2]; I need to define a kernel method that copies this data into user-space., so how would I go about defining this method? I've got the following, but I'm not quite sure what I'm doing. asmlinkage int sys_get_my_data(char __user ***data, int rowLen, int bufferSize) { ...

In C macros, should one prefer do { ... } while(0,0) over do { ... } while(0)?

A customer recently performed static analysis of my employer's C codebase and gave us the results. Among useful patches was the request to change the famous do { ... } while(0) macro to do { ... } while(0,0). I understand what their patch is doing (using the sequence operator to return evaluate to the value of the second "0", so the effe...

A floating point array in C

i am developing a code where i have to load floating point values stored in each line at a time in a text file...i loaded each of these data into a array of floats using fscanf()...however i found that the floating points were stored in a different way, example 407.18 was stored as 407.179993, 414.35 as 414.350006...now i am stuck becaus...

Complete online reference for the C standard library?

Have any of you got a link to an online reference that completely decribes the C(99) standard library? When i say describes, i mean something i can keep open and refer to when im coding. I'm looking for something along the lines of DevGuru ECMA script Reference but for the C standard library. ...

Adding effects to a MP4 Video?

I'd like to do several things to a MP4 video, but I am not sure where to start. Some things I'd like to do: - Change the color of the video to Black & White, Sepia, etc. - Add animations, such as fade in, fade out, custom images/text moving around - Embed text into the video Essentially, the basic features of a video editing program....

64 bit shared memory segment C \ linux problems

Hi, I'm looking to do some IPC with shared memory segments in C \ Linux. I go on creating it like normal : typedef struct { int a[2]; } shm_segment; ... shm_segment *shm; int shm_id; int shm_flags = IPC_CREAT | 0666 int shm_size = sizeof(struct shm_segment) key_t key = 88899; shm_id = shmget(key, shm_size, shm_flags); // ies t...

How to put a final summary message in a yacc program?

When I redirect input to my yacc program from an input file, after it finishes parsing the file I want the yacc parser to print a summary of what it did. I want it to do the same thing if I am entering input through the keyboard and then I press Ctrl-D. Is there a way to do that? ...

sending formatted messages across TCP connection

I have an existing C program which prints a number of messages to standard error using: fprintf(stderr, ... I would like to modify this program so that these messages are also sent out over a TCP connection across the Internet. (Which I have already created as a SOCK_STREAM socket.) What's the best way format the messages like they wo...