-
文件打開和關(guān)閉
這里的“打開”和“關(guān)閉”可調(diào)用標(biāo)準(zhǔn)庫(kù) stdio.h 中的 fopen 和 fclose 函數(shù)實(shí)現(xiàn)。
如:FILE * fopen(char *filename, char *mode);
filename:文件路徑
mode:文件打開模式 (r:只讀)(w:寫)(“rw” 表示讀寫)(rb:二進(jìn)制讀)(wb:二進(jìn)制寫)
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();
}