Posted on 2006-10-18 16:50 
neter 阅读(818) 
评论(1)  编辑 收藏 引用  所属分类: 
程序设计 
			 
			
		 
		闲暇无事,写点代码以打发无聊的时间。
 1 #include <stdio.h>
#include <stdio.h>
 2 #include <stdlib.h>
#include <stdlib.h>
 3
 4 int main(void)
int main(void)
 5

 {
{
 6 FILE *in,*out;
    FILE *in,*out;
 7 
    
 8 int block;
    int block;
 9 char *buffer;
    char *buffer;
10 int i;
    int i;
11 long size;
    long size;
12 int num = 1;
    int num = 1;
13 char src[32],dest[32],temp[32];
    char src[32],dest[32],temp[32];
14 printf("***********************************************\n");
    printf("***********************************************\n");
15 printf("请输入要分割的文件的位置:  ");
    printf("请输入要分割的文件的位置:  ");
16 scanf("%s",src);
    scanf("%s",src);
17 printf("请输入要分割成的小文件的个数:  ");
    printf("请输入要分割成的小文件的个数:  ");
18 scanf("%d",&num);
    scanf("%d",&num);
19 printf("请输入要分割后文件保存位置:  ");
    printf("请输入要分割后文件保存位置:  ");
20 scanf("%s",dest);
    scanf("%s",dest);
21 if ((in = fopen(src,"rb")) == NULL)
    if ((in = fopen(src,"rb")) == NULL)
22
 
     {
{
23 printf("Open File Fail\n");
        printf("Open File Fail\n");
24 exit(0);
        exit(0);
25 }
    }
26 fseek(in,0L,2);
    fseek(in,0L,2);
27 size = ftell(in);
    size = ftell(in);
28 rewind(in);
    rewind(in);
29 block = size/num; // 每一个文件的大小
    block = size/num; // 每一个文件的大小
30 buffer = (char*)malloc(block);
    buffer = (char*)malloc(block);
31
32 for(i=0;i< num;i++)
    for(i=0;i< num;i++)
33
 
     {
{
34 char ch[32];
        char ch[32];
35 strcpy(temp,dest);
        strcpy(temp,dest);
36 itoa((i+1),ch,10);
        itoa((i+1),ch,10);
37 strcat(temp,ch);
        strcat(temp,ch);
38 strcat(temp,".dat");
        strcat(temp,".dat");
39 if(fread(buffer,block,1,in)!=1)
        if(fread(buffer,block,1,in)!=1)
40
 
         {
{
41 printf("Read File Error\n");
            printf("Read File Error\n");
42 exit(0);
            exit(0);
43 }
        }
44 if((out = fopen(temp,"wb")) == NULL)
        if((out = fopen(temp,"wb")) == NULL)
45
 
         {
{
46 printf("Open File Fail\n");
            printf("Open File Fail\n");
47 exit(0);
            exit(0);
48 }
        }
49 if(fwrite(buffer,block,1,out)!=1)
        if(fwrite(buffer,block,1,out)!=1)
50
 
         {
{
51 printf("Write File Error\n");
            printf("Write File Error\n");
52 exit(0);
            exit(0);
53 }
        }
54 fclose(out);
        fclose(out);
55 }
    }
56 fclose(in);
    fclose(in);
57 free(buffer);
    free(buffer);
58 printf("Cut Over\n");
    printf("Cut Over\n");
59 printf("***********************************************\n");
    printf("***********************************************\n");
60 return 0;
    return 0;
61 }
}
62
 简单就是美的了。