#include <stdio.h>
int feof(FILE *stream);
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[])
{
FILE *fp;
char combuf[512];
char *pbuf = combuf;
if (!(fp = fopen(argv[1], "r"))) {
perror ("fopen error");
exit (EXIT_FAILURE);
}
memset (combuf, 0, 512);
while (!feof(fp)) {
*pbuf++ = fgetc (fp);
}
fclose(fp);
printf ("%s\n", combuf);
return (0);
}
$ ./readtest test.txt
hello world
�
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |