-
文件打开和关闭
这里的“打开”和“关闭”可调用标准库 stdio.h 中的 fopen 和 fclose 函数实现。
如:FILE * fopen(char *filename, char *mode);
filename:文件路径
mode:文件打开模式 (r:只读)(w:写)(“rw” 表示读写)(rb:二进制读)(wb:二进制写)
void main(){
FILE *fp1, *fp2;
fp1=fopen("D:\\VisualStudio\\work_place\\text01.txt", "r");
fp2 = fopen("D:\\VisualStudio\\work_place\\text02.txt", "w");
if (NULL==fp1){
printf("Failed to open the file !\n");
exit(0); //终止程序,stdlib .h头文件中
}
if (NULL == fp2){
printf("Failed to open the file !\n");
exit(0); //终止程序,stdlib .h头文件中
}
fclose(fp1);
fclose(fp2);
getchar();
}