I'm trying to get the last word from each line in a file using strtok(). I know how to step through each line in the file but I am having trouble getting the last word of the line.
The line looks like this:
so far I have this:
Code:
char *token = strtok(line, " ");
while (token != NULL)
{printf("%s\n", token);
token = strtok(NULL, " ");
}
The output:
I'm printing out each word to see what I'm doing. Ultimately I would like to store the last word in a variable. I'm just not sure how to get the last word.