c

Objective C - Are SystemSoundID's (typedef'd UInt32) automatically assigned 0?

- (void)playAlarmSound:(NSTimer *)theTimer { static SystemSoundID soundID/* = 0 */; // ? if (!soundID) { soundID = [Utilities createSystemSoundIDFromFile:@"beep" ofType:@"caf"]; } ... } Is SystemSoundID (which is a UInt32) automatically assigned 0? or should I explicitly assign it? I have to do it this way and t...

How to end a loop early in C?

I have a basic C program that produces a number and the user has to guess it (yup, you've already called it: homework). I am able to get pretty much all of it so I am kinda proud, but I open to any errors I have made of course I am still learning. My main two questions are How can I end this program early once the user has selected the...

Winsock UDP packets being dropped?

We have a client/server communication system over UDP setup in windows. The problem we are facing is that when the throughput grows, packets are getting dropped. We suspect that this is due to the UDP receive buffer which is continuously being polled causing the buffer to be blocked and dropping any incoming packets. Is it possible th...

How to reformat space delimited lines of text into separate <div> tags in C language?

Guys, I need to be able to (in C language) loop over a few lines of text where each line has some text in it where words are delimited by a variable number of white spaces. How can I detect the spaces and split each line into some kind of array so that I can put each word in a separate word tag in each line? Any advice would be much ap...

What's the rationale behind headers?

I don't quite understand the point of having a header; it seems to violate the DRY principle! All the information in a header is (can be) contained in the implementation. ...

Creating an "overlay" onto a window

Is it possible to create a window that acts as an overlay on top of another window, say, an icon that you can display in the window's title bar or status bar? Assume for the purposes of this question that: The window is a foreign window (not owned by my application) The overlay is 16x16 pixels and has a transparent background The over...

How can I erase the current line printed on console in C ? I am working on a linux system

How can I erase the current line printed on console in C ? I am working on a linux system example - printf("hello"); printf("bye"); I want to print bye on the same line in place of hello. output bye ...

How to create directories using the C standard library (or otherwise) ?

Help appreciated. Couldn't find any mention of this in "the book" (k&r). ...

How do I parse out the fields in a comma separated string using sscanf while supporting empty fields?

I have a comma separated string which might contain empty fields. For example: 1,2,,4 Using a basic sscanf(string,"%[^,],%[^,],%[^,],%[^,],%[^,]", &val1, &val2, &val3, &val4); I get all the values prior to the empty field, and unexpected results from the empty field onwards. When I remove the expression for the empty field from th...

How to copy char *str to char c[] in C?

Trying to copy a char *str to char c[] but getting segmentation fault or invalid initializer error. Why is this code is giving me a seg fault? char *token = "some random string"; char c[80]; strcpy( c, token); strncpy(c, token, sizeof c - 1); c[79] = '\0'; char *broken = strtok(c, "#"); ...

Why is this C code giving me a seg fault?

Possible Duplicate: How to copy char *str to char c[] in C? char *token = "some random string"; char c[80]; strncpy(c, token, sizeof c - 1); c[79] = '\0'; char *broken = strtok(c, "#"); ...

How can we find out the job ID of a process in C ?

Does the shell allocates a job ID to all processes(foreground and background)? jobs command shows the existing background jobs. How do we see job ID of foreground process? I want to use a function in C (like getpid()) to get the job ID and status of a given process given the pid of the process. What is the maximum value of a job ID? ...

Why is control going inside IF?

char *token = "gkjsdhvcxvcvbcbcv" char c[90]; strcpy( c, token); c[sizeof(c)-1] = '\0'; char *broken = strtok(c, " "); if ( broken != NULL) { //Should not come here as there is no white space??? } ...

Can we start a background process using exec() giving & as an argument?

If not, how can we start a background process in C? ...

Using strtok() in a loop in C?

I am trying to use strtok() in nested loop. But this is not giving me desired results. Possibly because they are using same memory location. My code is of the form:- char *token1 = strtok(Str1, "%"); while(token1 != NULL ) { char *token2 = strtok(Str2, "%"); while(token2 != NULL ) { //DO SMTHING token2 = strtok(NULL, ...

Monitor CPU load on XP programmatically

Is there a way to fetch the system cpu load in windows xp via a DLL call or other means. I would like to embed the call in my program and when the CPU load hits 100% I would like to capture the time. My program is maxes out cpu load every couple of days, and I would like to figure out precisely when so I can do a data dump and analyze th...

I don't understand itoa() in K&R book

I am reading K so far I'm doing well with it, but there is something in function itoa() which I don't understand. Here in itoa() they say they reverse the numbers themselves. For example 10 is 01 (they reverse the string): void itoa(int n, char s[]) { int i, sign; if ((sign = n) < 0) /* record sign */ n = -n; /* make n p...

How to initialize char array and empty it again and again in a loop before strcpy() in C?

I want to reinitialize d everytime in a loop char d[90]; while(ptr != NULL) { printf("Word: %s\n",ptr); //int k = 0; strcpy(d, ptr); d[sizeof(d)-1] = '\0'; //something more .... .... } ...

Why can't I do ++i++ in C-like languages?

Half jokingly half serious: why can't I do ++i++ in C-like languages, specifically in C#? I'd expect it to increment the value, use that in my expression, then increment again. ...

Where can I find a Lisp reader in C?

I have a Lisp reader written in Java that I'm thinking of translating into C. (Or perhaps C++.) It's a fairly complete and useful hack, so the main issue is doing the dynamic-storage allocation in a language without garbage collection. If someone has already thought this through I'd rather borrow their code than figure it out myself. ...