文件的打开与关闭+输入输出

时间:2021-04-19 00:59:25
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<errno.h>

int main() {
//打开
FILE* pf = fopen("F:\\QQ\\Download\\test.txt", "r");//写的时候,r换位w,此处为了防止转义字符,写成\\再次转义一次
//判断
if (pf == NULL) {
printf("%s", strerror(errno));
return 0;
}
//写
//fputc('s', pf);
//fputc('e', pf);
//fputc('e', pf);
//读
printf("%c", fgetc(pf));
printf("%c", fgetc(pf));
printf("%c\n", fgetc(pf));
//关闭
fclose(pf);
pf = NULL;

return 0;
}