I am unfortunately a complete novice when it comes to C. I am trying to read a text file which is formatted something like this
one two three
two one three
three one
I need to read the first string on a line (so in case of first line that would be "one", then I do a comparison with a variable. If its a match then I need to use rest of the string, so if a match on string one I need to use "two" and "three" (separately as their own strings). If there is no match I move on to the next line and so on.
Here is the code I have so far, but it doesnt seem to work. In comments what I think the code is doing.
char temp[] = "three";
while(!feof(file)){ //Go until end of file is reached
fgets(line, 100, file); //Grab the line
string_token = strtok(line, " "); //Tokenize the line
strcpy (compare_to, string_token); //Copy first token into a string variable
if (strcmp(compare_to, temp) == 0){ //Compare string with a predefined temp variable
while (string_token != NULL) { //If it was a match then we go until tokens end (which would be end of the line from a file)
printf("%s has the following: %s\n", temp,compare_to );
string_token = strtok(NULL, " ");
}
}
}