嗨,伙计们还没有找到如何在任何地方搜索文本文件中的特定单词,所以就在这里,这就是我现在所拥有的,只需阅读并打印整个文本文件。
#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