I'm suggesting using fgets() to grab the input line. This way you can limit the number of characters read in, and you won't overflow an array buffer (assuming you do it correctly).
Originally posted by MadStrum!
You're suggesting that I read each line using fgets and then process it internally using sscanf ?
How you do process the buffer depends on what you want to do with it.
But if you want the quick solution, yes, you can use sscanf(). Here's a sample to get you going.
I suppose you could use fscanf() instead (as you suggested). It all comes down to what you want to do with the data and how much you trust it to be formatted correctly.
char *p = buf;
if (fgets(buf, BUFSIZ, stdin) != NULL)
while (sscanf(p, "%30s%n", word, &wordlen) == 1)
printf ("Word %d >%s<\n", wordlen, word);
p += wordlen;