I am looking through a data file containing both words and numbers, and I need to take the numbers out of each row and store them in an array.
Cheryl 2 1 0 1 2 0
Neal 0 0 2 0 2 0
Henry 0 2 2 0 2 0
Lisa 0 0 0 0 2 1
This is how the file is formatted. I start by inputting each line into an array, participants[], and then I need to take the numbers from each line and put them in a separate, two-dimensional array, individually. i.e. the first line would be translated to:
responses[0][0] = 2
responses[0][1] = 1
responses[0][2] = 0
responses[0][3] = 1
responses[0][4] = 2
responses[0][5] = 0
At this point, I detect the first space with char *pointer = strstr(" ", participants[]);, and am able to locate the the beginning of the numbers with strcpy(temp, pointer+1);.
From that point, I run into problems as I am having a hard time translating the string of numbers (still a char string), into individual integer values to be stored in my responses[][] array.
Thanks!
strtoul(). That might even take care of the tokenization for you if you play it right.endptrargument to figure out where the next number starts.