C语言文件操作(三)

时间:2014-05-12 03:47:54   收藏:0   阅读:244

实例3:读写字节文件,每次读入一个缓存里面。

#include<stdio.h>

#include <stdlib.h>

#define MAXLEN 1024

int main()

{

   FILE *fpin ;

   FILE *fpout;

   unsigned char buf[MAXLEN];


   int c;

   fpout=fopen("c:\\dest.jpg","wb");

   if((fpin=fopen("c:\\test.jpg","rb"))!=NULL)

   {

      c = fread(buf,sizeof(unsigned char),MAXLEN,fpin);

      while(c!=0)

      {

         fwrite(buf,sizeof(unsigned char),c,fpout);

         c=fread(buf,sizeof(unsigned char),MAXLEN,fpin);

      }

   }

   else

   {

      printf("file not exist!");

      exit(1);

    }

    fclose(fpin);

    fclose(fpout);


    return 0;

}


C语言文件操作(三),布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!