hi i need a litle help.....i must write a program that search for a string in a text file and return the line in the text file were string was found...string its an argv....i wrote this code but it returns the whole text file when i search for something
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(int argc,char *argv[])
{ char caracter[255];
FILE *f;
if(!(f=fopen("File.txt","r")))
{printf("nu este fisierul corect");
exit(1);
}
if(argc>0){
while( fgets(caracter,254,f) !=NULL)
{
if(strcmp(caracter,argv[1]))
printf("%s \n",caracter);
else printf("NOT FOUND");
}
}
return 0;
}