I'm making a program that accepts a number and then parses the a file to return the name associated with that number. It's mostly done, but there's just one last step. Right now, my program correctly finds the line associated with the given number by checking the first token of every line. Here's a snippet of the code that matters:
while (fgets(line, 50, f)) {
tok = strtok(line, " ");
if (n == atoi(tok))
{
printf(" %s\n", tok);
return 0;
}
}
Right now it just prints the first token, which is great because that means it found the right line. However, I need it to print the last token, but I can't figure out how to do that with strtok()
. Could someone help me out?