C語言文件操作(一)

實例1:讀寫字符文件,每次讀取一個字符。

#include<stdio.h>

#include <stdlib.h>

int main()

{

   FILE *fpin ;

   FILE *fpout;

   char c;

   fpout=fopen("c:\\dest.txt","wt");

   if((fpin=fopen("c:\\test.txt","rt"))!=NULL)

   {

      c = fgetc(fpin);

      while(c!=EOF)

      {

         fputc(c,fpout);

         c=fgetc(fpin);

      }

   }

   else

   {

       printf("file not exist!");

       exit(1);

    }

   fclose(fpin);

   fclose(fpout);


   return 0;

}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章