/* p11d.c */ /* Demonstrates how to acquire numeric data from lines of input that look like: XX 1 aadf adsf 2 4 adfasdf XX 33 adf 55 asdfd 66 adad 67 68 */ #include #include #include main() { unsigned char *buf; int line = 0; unsigned char *start; unsigned char *stop; int val; /* allocate a buffer large enough to hold a single line */ buf = (unsigned char *)malloc(1024); if (buf == 0) exit(1); while (fgets(buf, 1024, stdin) != 0) { stop = buf; /* or start = &buf[3] */ do { start = stop; val = strtol(start, &stop, 0); if (start != stop) printf("%5d \n", val); else stop += 1; } while (*stop != 0); } }