70,023
社区成员




#include <stdio.h>
#include <string.h>
#define MAX_LEN 1024
int tailf(FILE* fp, char* buf)
{
while(1)
{
sleep(2);//防止打印信息出现过快
memset(buf, 0 ,MAX_LEN);
if(NULL == fgets(buf,MAX_LEN,fp))
{
printf("没有读到新内容\n");
}
else
{
printf("%s", buf);
}
}
return 0;
}
int main(void)
{
char buf[MAX_LEN];
FILE* fp = NULL;
//打开测试文件
if(NULL == (fp = fopen("/home/d5000/sichuan/src/test/ll/data","rb")))
return -1;
//总从最后打开,有新增内容时,程序打印最新内容
if(-1 == fseek(fp, 0, SEEK_END))
return -2;
while(1)
{
tailf(fp, buf);
}
return 0;
}