-
文件打開和關閉
這里的“打開”和“關閉”可調用標準庫 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();
}