c语言中实现文件间的复制

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wwwww_bw/article/details/53471414
#include <stdio.h>
#include <malloc.h>
#define bytes (1024*3)
int main()
{
    FILE *fp;
    FILE *tp;
    int i;
    int f_file;
    char *p;
    //char string[bytes];
    p = (char*)malloc(bytes*sizeof(char));
    fp = fopen("file.c","rb");
    tp = fopen("c3","wb");
    fseek(fp,0,SEEK_END);
    f_file = ftell(fp);
    fseek(fp,0,SEEK_SET);
   
    printf("%d\n",f_file);
    while(!feof(fp))
    {
       fread(p,bytes,1,fp) ;
       printf("%d\n",fread(p,bytes,1,fp));
       if(bytes > f_file)
       {
           fwrite(p,f_file,1,tp);
       }
       else
       {
            fwrite(p,bytes,1,tp);
            f_file = f_file - bytes;
       }
      // memset(p,0,bytes);
    }
    fseek(tp,0,SEEK_END);
    f_file = ftell(tp);
    printf("%d\n",f_file);
    fclose(fp);
    fclose(tp);
}

猜你喜欢

转载自blog.csdn.net/wwwww_bw/article/details/53471414