我试图把Stdin写成文件 但不知为何,我读了零字节
来源:
#include <stdio.h>
#include <stdlib.h>
#define BUF_SIZE 1024
int main(int argc, char* argv[]) {
if (feof(stdin))
printf("stdin reached eof
");
void *content = malloc(BUF_SIZE);
FILE *fp = fopen("/tmp/mimail", "w");
if (fp == 0)
printf("...something went wrong opening file...
");
printf("About to write
");
int read;
while ((read = fread(content, BUF_SIZE, 1, stdin))) {
printf("Read %d bytes", read);
fwrite(content, read, 1, fp);
printf("Writing %d
", read);
}
if (ferror(stdin))
printf("There was an error reading from stdin");
printf("Done writing
");
fclose(fp);
return 0;
}
我正在运行 cct test.c\\ \ \ \ / test
并且输出只是
About to write
Done writing
似乎读了零字节 虽然我有很多东西