Chinaunix首页 | 论坛 | 博客
  • 博客访问: 474872
  • 博文数量: 280
  • 博客积分: 337
  • 博客等级: 二等列兵
  • 技术积分: 1957
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-17 21:36
文章分类

全部博文(280)

文章存档

2017年(13)

2016年(38)

2015年(78)

2014年(67)

2013年(70)

2012年(14)

分类: C/C++

2013-02-28 14:16:20


点击(此处)折叠或打开

  1. #include <iostream>
  2. #include <cstdio>

  3. void division_file(FILE *fp_src, FILE *fp_dst)
  4. {
  5.     int n = 0;
  6.     char *buf = (char*)malloc(1024*1024);
  7.     if(!buf)
  8.     {
  9.         printf("malloc 1m failed: %m!n");
  10.         return;
  11.     }
  12.     for(int i = 0; i < 1024; i++)
  13.     {
  14.         
  15.         if(!feof(fp_src))
  16.         {
  17.             memset(buf, 0, sizeof(buf));
  18.             n = fread(buf, 1, 1024*1024, fp_src);        
  19.             fwrite(buf, 1, n, fp_dst);
  20.             //printf("make file i: %d n: %dn", i, n);
  21.         }
  22.     }
  23.     free(buf);
  24. }

  25. int main(int argc, char **argv)
  26. {
  27.     FILE *fp, *fp_dst;
  28.     char tmp_name[512] = {0};
  29.     char buf[4096] = {0};
  30.     if(argc < 2)
  31.         return 1;

  32.     fp = fopen(argv[1], "rb");
  33.     if(!fp)
  34.         return 1;

  35.     strcpy(tmp_name, argv[1]);
  36.     //printf("argv[1]: %sn", argv[1]);
  37.     for(int i = 1; !feof(fp); i++)
  38.     {
  39.         if(i < 10)
  40.         {
  41.             tmp_name[strlen(argv[1])] = '0' + i;    
  42.         }
  43.         else
  44.         {
  45.             tmp_name[strlen(argv[1])] = '0' + i/10;    
  46.             tmp_name[strlen(argv[1])+1] = '0' + i%10;    
  47.         }
  48.         //printf("tmp_name: %sn", tmp_name);
  49.         fp_dst = fopen(tmp_name, "wb+");
  50.         if(!fp_dst)
  51.             break;
  52.         div

    点击(此处)折叠或打开

    1. #include <iostream>
    2. #include <cstdio>

    3. void combile_file(FILE *fp_src, FILE *fp_dst)
    4. {
    5.     int n = 0;
    6.     char *buf = (char*)malloc(1024*1024);
    7.     if(!buf)
    8.     {
    9.         printf("malloc 1m failed: %m!n");
    10.         return;
    11.     }
    12.     while(!feof(fp_src))
    13.     {
    14.         memset(buf, 0, sizeof(buf));
    15.         n = fread(buf, 1, 1024*1024, fp_src);        
    16.         fwrite(buf, 1, n, fp_dst);
    17.     }
    18.     free(buf);
    19. }

    20. int main(int argc, char **argv)
    21. {
    22.     if(argc < 2)
    23.         return 1;
    24.     
    25.     FILE *fp, *fp_dst;
    26.     char tmp_name[512] = {0};
    27.     
    28.     fp_dst = fopen(argv[1], "wb+");
    29.     //printf("argv[1]: %sn", argv[1]);
    30.     if(!fp_dst)
    31.         return 1;

    32.     strcpy(tmp_name, argv[1]);

    33.     for(int i = 1; ; i++)
    34.     {
    35.         if(i < 10)
    36.         {
    37.             tmp_name[strlen(argv[1])] = '0' + i;    
    38.         }
    39.         else
    40.         {
    41.             tmp_name[strlen(argv[1])] = '0' + i/10;    
    42.             tmp_name[strlen(argv[1])+1] = '0' + i%10;    
    43.         }
    44.         //printf("tmp_name: %sn", tmp_name);
    45.         fp = fopen(tmp_name, "rb");
    46.         if(!fp)
    47.             break;
    48.         combile_file(fp, fp_dst);
    49.         fclose(fp);
    50.         printf("combine_file "%s" into "%s"n", argv[1], tmp_name);
    51.     }

    52.     fclose(fp_dst);
    53.     printf("press any key to continue!n");
    54.     getchar();
    55.     return 0;
    56. }

    ision_file(fp, fp_dst);
  53.         fclose(fp_dst);
  54.         printf("division_file "%s" into "%s"n", argv[1], tmp_name);
  55.     }
  56.     
  57.     fclose(fp);
  58.     printf("press any key to continue!n");
  59.     getchar();
  60.     return 0;
  61. }

点击(此处)折叠或打开

  1. #include <iostream>
  2. #include <cstdio>

  3. void combile_file(FILE *fp_src, FILE *fp_dst)
  4. {
  5.     int n = 0;
  6.     char *buf = (char*)malloc(1024*1024);
  7.     if(!buf)
  8.     {
  9.         printf("malloc 1m failed: %m!n");
  10.         return;
  11.     }
  12.     while(!feof(fp_src))
  13.     {
  14.         memset(buf, 0, sizeof(buf));
  15.         n = fread(buf, 1, 1024*1024, fp_src);        
  16.         fwrite(buf, 1, n, fp_dst);
  17.     }
  18.     free(buf);
  19. }

  20. int main(int argc, char **argv)
  21. {
  22.     if(argc < 2)
  23.         return 1;
  24.     
  25.     FILE *fp, *fp_dst;
  26.     char tmp_name[512] = {0};
  27.     
  28.     fp_dst = fopen(argv[1], "wb+");
  29.     //printf("argv[1]: %sn", argv[1]);
  30.     if(!fp_dst)
  31.         return 1;

  32.     strcpy(tmp_name, argv[1]);

  33.     for(int i = 1; ; i++)
  34.     {
  35.         if(i < 10)
  36.         {
  37.             tmp_name[strlen(argv[1])] = '0' + i;    
  38.         }
  39.         else
  40.         {
  41.             tmp_name[strlen(argv[1])] = '0' + i/10;    
  42.             tmp_name[strlen(argv[1])+1] = '0' + i%10;    
  43.         }
  44.         //printf("tmp_name: %sn", tmp_name);
  45.         fp = fopen(tmp_name, "rb");
  46.         if(!fp)
  47.             break;
  48.         combile_file(fp, fp_dst);
  49.         fclose(fp);
  50.         printf("combine_file "%s" into "%s"n", argv[1], tmp_name);
  51.     }

  52.     fclose(fp_dst);
  53.     printf("press any key to continue!n");
  54.     getchar();
  55.     return 0;
  56. }


阅读(1012) | 评论(0) | 转发(1) |
0

上一篇:获取网络时间

下一篇:C++ class初始化

给主人留下些什么吧!~~