try this:
Code:
#include <stdio.h>
#include <string.h>
#define FILENAME "/home/lynux/test.txt" //file location
#define MAX 256 // MAX number of chars per line
int main()
{
FILE* fp;
char buf[MAX];
char* mystring = "search string here\n";
int lines=0;
fp = fopen(FILENAME,"r");
while(fgets(buf,MAX,fp))
if(!strcmp(buf,mystring))
{
printf("%s found on line %d\n",mystring,lines);
//fclose(fp);
//return 0;
//remove the above comments if you want to disregard the rest of the search
}
else
lines++;
fclose(fp);
return 0;
}