c

Figure out function argument from custom struct?

I have a function which takes a custom struct as the argument. how can I figure out what the argument should be? I know it is a date format of sorts... (C library imported to Objective-C...) Struct: typedef struct { /** The number of day in the hebrew month (1..31). */ int hd_day; /** The number of the hebrew month 1..14 (...

Can a pointer ever point to itself?

This question was mentioned here. My question is: If a pointer variable has the same address as its value, is it really pointing to itself? For example - in the following piece of code, is a a pointer to itself? #include<stdio.h> int main(){ int* a; int b = (int)&a; a = b; printf("address of a = %d\n", &a); printf(" ...

Stack Overflow problem in a recursive program in C

Hi all, I am getting a stack overflow in one of the recursive functions i am running.. Here is the code.. void* buddyMalloc(int req_size) { // Do something here return buddy_findout(original_index,req_size); // This is the recursive call } void *buddy_findout(int current_index,int req_size) { char *selected = NULL; ...

File in binary form

Dear All I want to write data into the file in binary form. I was trying using the mentioned below FILE *fp = fopen("binaryoutput.rgb888", "ab+"); for(int m=0; m<height; m++) { for (int n=0; n< width; n++) { temp = (pOutputImg+m*3+n*3); // here pOutputImg & temp is a pointer to a unsigned...

How to move file pointer to a particular location using fseek()?

My intention is to read every elements in the 2nd column into a buffer[] from the following .txt file: 9992891234 09.920 15.771 11.909 9992345971 07.892 12.234 09.234 9992348971 64.567 70.456 50.987 9992348231 89.234 85.890 58.982 I have know of a way to do it by using fscanf(): for (int i=0;i<4;i++) { fscanf(p...

[C] Read line from file without knowing the line length.

Hi, I want to read in a file line by line, without knowing the line length before. Here's what I got so far: int ch = getc(file); int length = 0; char buffer[4095]; while (ch != '\n' && ch != EOF) { ch = getc(file); buffer[length] = ch; length++; } printf("Line length: %d characters.", length); char newbuffer[length + 1]...

How to init and malloc array to pointer on C

It looks like I have a memory leak when I try to initializ an array of pointers. This my code: void initLabelTable(){ register int i; hashNode** hp; labelHashTable = (hashNode**) malloc(HASHSIZE*sizeof(hashNode*)); hp = labelHashTable; for(i=0; i<HASHSIZE; i++) { *(hp+i) = NULL; } } Any idea? ...

are posix pipes lightweight?

In a linux application I'm using pipes to pass information between threads. The idea behind using pipes is that I can wait for multiple pipes at once using poll(2). That works well in practice, and my threads are sleeping most of the time. They only wake up if there is something to do. In user-space the pipes look just like two file-h...

glib on Symbian S60

Hello, I am interested in porting a C library that depends on glib to Symbian. After some research, I found that there is a Symbian port of glib. However I can't seem to find much documentation about it. Can anyone point me to the right direction as to whether this can be even done or not? If yes, how. ...

"C variable type sizes are machine dependent." Is it really true? signed & unsigned numbers ;

Hello, I've been told that C types are machine dependent. Today I wanted to verify it. void legacyTypes() { /* character types */ char k_char = 'a'; //Signedness --> signed & unsigned signed char k_char_s = 'a'; unsigned char k_char_u = 'a'; /* integer types */ int k_int = 1; /* Same as "signe...

How to find the current line position of file pointer in C?

How can I get the current line position of the file pointer? ...

How to Join N live MP3 streams into one using FFMPEG?

How to Join N live MP3 streams (radio streams like such live KCDX mp3 stream http://mp3.kcdx.com:8000/stream ) into 1 using FFMPEG? (I have N incoming live mp3 streams I want to join them and stream out 1 live mp3 stream) I mean I want to mix sounds like thay N speakers speak at the same time (btw N stereo to 1 mono), please help. BTW: ...

How can c let a function declaration with any parameter type ?

I forgot to write void parameter but it works the i put void it gives error it lets this: print(int size,int table[size][size]){ int i,j; printf("-------TABLE-------\n"); for(i = 0;i<size;i++){ for(j = 0;j<size;j++){ if(table[i][j]==EMPTY) printf(". "); else printf("* "); } printf("\n"); ...

EPIPE blocks server

I have written a single-threaded asynchronous server in C running on Linux: The socket is non-blocking and as for polling, I am using epoll. Benchmarks show that the server performs fine and according to Valgrind, there are no memory leaks or other problems. The only problem is that when a write() command is interrupted (because the cli...

Using FFMPEG and url_fopen example

So I wonder how to get a streal from URL (with url_fopen for ex) (live video or PCM stream for example) and encode it into somsh? ...

Comparing strings with user-created string class

For this assignment I had to create my own string class. I initially wrote the compareto method to compare two string but return whichever is overall larger. What I want to do is compare and return which one is alphabetically larger i.e. comparing two strings, for example: smith and htims. With the way I designed the compareto method ...

Multiple threads or process with threads

Hi, this is for an assignment so I'm not looking for code. I have to simulate a game where each player has turns and needs to 'pay attention' to what's going on. So far, i know I'll need two threads for each player, one that will sleep until the player's turn and the other paying attention. My question is: Should I work each player as...

"volatile" qualifier and compiler reorderings

A compiler cannot eliminate or reorder reads/writes to a volatile-qualified variables. But what about the cases where other variables are present, which may or may not be volatile-qualified? Scenario 1 volatile int a; volatile int b; a = 1; b = 2; a = 3; b = 4; Can the compiler reorder first and the second, or third and the fourth ...

Looking for a smarter way to convert a Python list to a GList?

I'm really new to C -> Python interaction and am currently writing a small app in C which will read a file (using Python to parse it) and then using the parsed information to execute small Python snippets. At the moment I'm feeling very much like I'm reinventing wheels, for example this function: typedef gpointer (list_func)(PyObject *o...

How are delegates in C# better than function pointers in C/C++?

The delegates in C# offer similar functionality as function pointers in C. I heard someone saying "C# delegates are actually better than function pointers in C". How come? Please explain with an example. ...