Name: Anonymous 2009-08-29 8:56
I have a file in which ever line of text is terminated with a number. I'd like to extract the text and the number to variables, how do I do that?
int doit() {
char buf[64];
int n = 0;
size_t i, x = 1;
if(fgets(buf, 64, stdin)) {
i = strlen(buf);
while(i && isdigit((unsigned char)buf[--i]))
n += (buf[i] - '0') * x, x *= 10;
if(buf[i] == '-') return -n;
return n;
}
}