안녕하세요 사람들은 텍스트 파일에서 특정 단어를 검색하는 방법을 찾을 수 없었습니다. 그래서 여기에있는 내용이 제가 지금 가지고있는 것입니다. 전체 텍스트 파일을 읽고 인쇄합니다. . 텍스트 파일에서 특정 단어 검색
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main (void)
{
static const char filename[] = "chat.log";
FILE *file = fopen (filename, "r");
if (file != NULL)
{
char line [ 128 ]; /* or other suitable maximum line size */
while (fgets (line, sizeof line, file) != NULL) /* read a line */
{
fputs (line, stdout); /* write the line */
}
fclose (file);
}
else
{
perror (filename); /* why didn't the file open? */
}
return 0;
}
감사합니다 : D
'fgets (line, sizeof line, file)! = NULL','sizeof (line)' –