June 8th, 2003, 09:22 PM
Join Date: May 2003
Time spent in forums: < 1 sec
Reputation Power: 0
scanning a char buffer for integers
Need some help grabbing ints from a buffer.
I have a function that reads data from a file. the data is just a line of integers separated by spaces. I have this data in a char buffer. I know how many bytes were read into the buffer. What I have to do now, is scan the buffer, reading each integer one by one and performing something on each integer. The number of integers in one file can vary from another file. I want to use sscanf, but don't know how I can read all the integers. THis is my code:
char * buffer;
/*suppose the buffer has the data now, and size is the size of buffer*/
/*suppose x is a number that I determined at run-time*/
for(int i=0; i<numInts; i++)
sscanf(buffer, "%i", &num);
//do something to num
How can I scan the buffer so that the pointer to buffer is actually moving, and not reading the same number in each iteration?