Originally posted by WebmasterMattD
Code:
while (fgets(temp, 100, document)) {
if( strstr(searchfor, temp) ) {
printf("%s", temp);
}
}
This is wrong I believe. Check your documentation on strstr, but mine says you do it this way:
Code:
strstr(lookinhere, lookforthis);
Here's some working code for you to ponder:
Code:
#include <stdio.h>
#include <string.h>
int main(void)
{
char *lines[] = {"this is line one", "and I am 2", "and I am line 3"};
char criteria[] = "line";
int i;
for (i = 0; i < 3; i++)
{
if (strstr(lines[i], criteria))
printf("%s\n", lines[i]);
}
return (0);
}
It simply searches the 3 lines, looking for the word line. If it finds it, it prints it.