Everything is a file
“读”就是从文件里获取数据,“写”则相反,是将数据写入到文件里面。
在完成对一个文件的读写操作之后,你必须将其关闭
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
FILE *fp;
int ch;
if((fp = fopen("hello.txt", "r")) == NULL)
{
printf("打开文件失败!\n");
exit(EXIT_FAILURE);
}
while ((ch = getc(fp)) != EOF)
{
putchar(ch);
}
fclose(fp);
return 0;
}