C语言-文件读写
#include
int main() {
//1. 打开文件
FILE* fr = fopen("C:\\Users\\hp\\Desktop\\hi.txt", "r");
FILE* fw = fopen("C:\\Users\\hp\\Desktop\\hello.txt", "w");
if (fr == NULL || fw == NULL) {
printf("文件打开失败");
return 0;
}
//2.读写文件
char buffer[128];
while (fgets(buffer, 128, fr)) {//获取fr(hi.txt)中的字符串存入buffer
fputs(buffer, fw); //将buffer中的字符串存入fw(hello.txt)
}
//3.关闭文件
fclose(fr);
fclose(fw);
return 0;
}