- 论坛徽章:
- 0
|
有如下代码:
- #include <stdio.h>;
- #include <stdlib.h>;
- int main(int argc, char *argv[])
- {
- char line[1024];
- FILE *fp;
- fp = freopen("test.txt", "a+", stdout);
- if (fp == NULL)
- {
- perror("freopen");
- exit(-1);
- }
- fprintf(stderr, "file(fp) length = %ld\n", ftell(stdout));
- fprintf(stderr, "file(stdout) length = %ld\n", ftell(fp));
- fprintf(stdout, "this is a test\n");
- fflush(NULL);
- fprintf(stderr, "file(fp) length = %ld\n", ftell(stdout));
- fprintf(stderr, "file(stdout) length = %ld\n", ftell(fp));
- while(fgets(line, 1024, stdout) != NULL)
- {
- fprintf(stderr, "%s", line);
- }
- if (feof(stdout))
- fprintf(stderr, "fgets eof\n");
- else
- {
- fprintf(stderr, "fgets error\n");
- }
- exit(0);
- }
复制代码
当我在Linux下运行时(版本:Linux localhost.localdomain 2.2.16-3 #2 |
|