Reading already opened file continuously using C

空扰寡人 提交于 2019-12-01 11:49:50

Try something like this:

for (;;) {
    while ((ch = getc(fp)) != EOF)  {
        if (putchar(ch) == EOF)
            perror("Output error");
    }
    if (ferror(fp)) {
        printf("Input error: %s", errno);
        return;
    }
    (void)fflush(stdout);
    sleep(1); // Or use select
}

You can find a full example by studying the source code for tail. The code above is a modified excerpt from forward.c.

You can use select to monitor several files for new data (you need to keep them open).

Give a try with rewind() and don't close your file.

once you complete read operation,close your file there.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!