标签:style http io ar color os 使用 sp for
#include<stdio.h>#defineF_PATH"d:\\myfile\\file.dat"intmain(void){FILE*fp=NULL;//需要注意fp=fopen(F_PATH,"r");if(NULL==fp){return-1;//要返回错误代码}fclose(fp);fp=NULL;//需要指向空,否则会指向原打开文件地址return0;}#include<stdio.h>#include<stdlib.h>//为了使用exit()intmain(){charch;FILE*fp=NULL;charfname[50];//用于存放文件名printf("输入文件名:");scanf("%s",fname);fp=fopen(fname,"r");//只供读取if(fp==NULL)//如果失败了{printf("错误!");exit(1);//中止程序}while((ch=getc(fp))!=EOF)putchar(ch);fclose(fp);//关闭文件return0;}#include<stdio.h>FILE*stream,*stream2;intmain(void){intnumclosed;//Openforread(willfailiffile"crt_fopen.c"doesnotexist)if((stream=fopen("crt_fopen.c","r"))==NULL)//C4996//Note:fopenisdeprecated;considerusingfopen_sinsteadprintf("Thefile‘crt_fopen.c‘wasnotopened\n");elseprintf("Thefile‘crt_fopen.c‘wasopened\n");//Openforwriteif((stream2=fopen("data2","w+"))==NULL)//C4996printf("Thefile‘data2‘wasnotopened\n");elseprintf("Thefile‘data2‘wasopened\n");//ClosestreamifitisnotNULLif(stream){if(fclose(stream)){printf("Thefile‘crt_fopen.c‘wasnotclosed\n");}}//Allotherfilesareclosed:numclosed=_fcloseall();printf("Numberoffilesclosedby_fcloseall:%u\n",numclosed);}标签:style http io ar color os 使用 sp for
原文地址:http://www.cnblogs.com/sky-of-chuanqingchen/p/4123163.html