i am doing an exercise in C for my C programming course. I have to read data from a text file into a linked list and look for matches, then print the result out.
Example of the text file:
"Apple/Orange",1
"Banana/Watermelon/Lemon",2
"Watermelon/Strawberry",3
"Orange/Grape/Watermelon",4
"Blueberry", 5
Stored them into my linked list by using fgets(), sscanf() and a void function, therefore the string will be starting with a quotation mark.
The problem is when i tried to use strncmp() to find a word from the string, it didn't work due to the quotation mark.
I did something like:
void findFruits(List *list){
Node *position = list->first;
while(position != NULL){
if(strncmp(position->fruits, "Watermelon", 10)==0){
printf("%s, %d\n", position->fruits, position->number);
}
position = position->next;
}
I literally have no clue for finding an exact word from the string which is beginning with a quotation mark, any help would be appreciated, thanks.
Solved now, thanks to Barmar's idea. It worked perfectly when i tried to use strstr() instead of strncmp().
if(strstr(position->fruits, "Watermelon")){
printf("%s, %d\n", position->fruits, position->number);
}