Sorry for the late reply, I got caught up in stuff last night after work.
I think the best thing you can do at this point is to (1) determine the logical steps you need to accomplish your task, and (2) tackle each step by itself, one at a time.
For instance, based on your other posts in this thread, you're not very experienced with the "scanf" family of functions. So rather than assuming how they might work and building code around that, you should thoroughly examine their behavior with small sample programs.
For instance, the following code replicates the "extract individual strings from a line" approach you are trying to use.
Code:
#include <stdio.h>
#define MAX_LEN 8
int main(void)
{
char string[] = "test1, test2, test3, test4, test5\n";
char test[MAX_LEN] = {0};
sscanf(string,"%s",test);
printf("%s\n",test);
return 0;
}
/*
output:
test1,
*/
See that? It reads the first string including the comma. That makes sense, as "scanf("%s",...)" reads characters until it hits the first whitespace (space, tab, newline). So this is something you have to address before incorporating the code into your actual program.
One option would be to use the additional features of "scanf" to eliminate reading this comma.
Code:
#include <stdio.h>
#define MAX_LEN 8
int main(void)
{
char string[] = "test1, test2, test3, test4, test5\n";
char test1[MAX_LEN] = {0};
char test2[MAX_LEN] = {0};
char test3[MAX_LEN] = {0};
char test4[MAX_LEN] = {0};
char test5[MAX_LEN] = {0};
sscanf(string,"%[^,], %[^,], %[^,], %[^,], %[^,]",test1,test2,test3,test4,test5);
printf("%s\n",test1);
printf("%s\n",test2);
printf("%s\n",test3);
printf("%s\n",test4);
printf("%s\n",test5);
return 0;
}
(See about the "negated scanset" for scanf.) However, if you're unclear on the basics, this would probably not be the best approach for you.
Another option is "strtok", but again, this might be beyond your abilities at this time.
In your first post on this thread, you mentioned "fgetc". It's possible to write your own function that takes the entire line and parses it yourself, character by character. This might be the easiest approach for now.
Hopefully, you should have covered this topic in class. If so, you can use the methods you learned to complete this portion of code.
So, the point of all this is that you should take everything one step at a time. Break the problem down into smaller problems, and solve each one on its own. I would advise the following:
1. Write a simple program similar to the first one in this post. Just have a local array with a string that contains one line of your data file. Write the code you need to break that string into separate sub-strings and print them out. Do not advance until this works exactly as expected.
2. Grow your program to include another array. Read from stdin, parse that string, and print the results. Do not advance until this works exactly as expected.
3. Add code to your program that will compare the input from stdin with the data parsed from the string in step 1, and print a message indicating if it matches or not. Try different inputs, both correct and incorrect, and see that you get the desired results. Do not advance until this works exactly as expected.
4. Change your code so that instead of hard-coding the data string, you open the file and load the first line (all the parsing work you did should still work as is). Then test it as you did in step 3. (Note there is no need to add the loop yet - just test the very first line for now.) Do not advance until this works exactly as expected.
5. Now you can add the loop. After reading input from stdin, enter your loop which reads one line at a time from the data file and compares it to the input. If it's a match, print so and break out of the loop. If you reach the end of the file without a match, print so.
See how much more manageable this process becomes when you take it in little steps? It might seem like more work at first, but it greatly improves the chances that your program will work as expected as you get closer to finishing it. And this is a lot less time consuming than banging out a bunch of code and staring at it in confusion when it doesn't work.