Originally Posted by
matsp
The general method is that you have a flag variable (an integer or bool), and set the flag to "not found" before the loop. If you find what you are "not looking for", then mark it as found, and break the loop. After the loop, check if you found what you are "not looking for", and if it was NOT found, then store the name of the file [or, if you are not needing it later on, just print the name and be done with it].
This must be the solution for experts, because I don't understand it. Seems like reverse psychology.
As always, thanks for your help, Mats.
Here's a newbie solution that I came up with, which seems to work.
Code:
for( counter = 0; counter < lastfilenumber1; counter++)
{
if((p_openfile = fopen(LineData[counter].storefilename, "r")) == NULL)
{
perror("Error opening file");
exit(EXIT_FAILURE);
}
while((fgets(p_line, FILELINELENGTH, p_openfile)) != NULL)
{
if((p_searchstring = strstr(p_line, p_searchtext) != NULL))
{
strcpy(LineData[counter1].filename1, LineData[counter].storefilename);
counter1++;
break;
}
}
if((fgets(p_line, FILELINELENGTH, p_openfile)) == NULL)
{
strcpy(LineData[counter2].filename2, LineData[counter].storefilename);
printf("\n%s", LineData[counter2].filename2);
counter2++;
}
fclose(p_openfile);
}