I am using strtok() for the first time to tokenize a string from a file. From checking, I can sucessfully open then file and read the whole string from the file and input it into a string variable.
What I am having trouble with is tokenizing the string properly and storing it into a 2d string.
When I check by testing each iteration, I "print" through ncurses the same thing over and over agian. It seems that I am able to tokenize the first section of the string. However it seems that I cannot tokenize the next part of the string when moving to the next iteration.
Code:
/* iteration counter 1 */
int counterOne;
/* room value 2 dimensional string variable and initialization of first
dimension*/
char * * roomValue = malloc(sizeof(char *) *151);
/* iteration to initailize second dimension */
for(counterOne = 0; counterOne != 151; counterOne++)
{
roomValue[counterOne] = malloc(sizeof(char *) *151);
}
/* token string variable */
char * token = malloc(sizeof(char *) * 151);
/* parsing of file input sting string by iterarations */
for(counterOne = 0; counterOne != 151; counterOne++)
{
/* tokenize by iteration */
token = strtok(fileInput, " ");
/* copy token to room value string */
strcpy(roomValue[counterOne], token);
/* test per iteration */
mvaddstr(counterOne, 0,roomValue[counterOne]);
}
The only things I can think of is that:
a) I am not using strtok() correctly,
b) I am not coping the token to the 2d string correctly,
c) The logic that I am using is wrong?
I would really apprecaite some insight as to what the problem is. Also, thanks for taking time to help ahead of time!