我想在文本文件中搜索文本词。但是,代码不会在 while 循环内执行。fgets 定义有什么问题?我该如何解决?程序总是打印“while msg 之外”
char repeated_data [10] = "0123456789";
char temp[512];
FILE * fp5 = fopen("/home/eagle/Desktop/temp.txt","r");
if(fp5 == NULL)
{
perror("temp_network.txt open failed");
exit(EXIT_FAILURE);
}
//search the text inside the temp.txt
while(fgets(temp, 512, fp5) != NULL)
{
printf("while msg\n");
if((strstr(temp, repeated_data)) != NULL)
{
discard_message=1;
printf("msg is discarded msg\n");
}
printf("inside of while\n");
}
fclose(fp5);
printf("outside of while msg\n");