Posted on 2006-10-18 16:50
neter 閱讀(800)
評(píng)論(1) 編輯 收藏 引用 所屬分類(lèi):
程序設(shè)計(jì)
閑暇無(wú)事,寫(xiě)點(diǎn)代碼以打發(fā)無(wú)聊的時(shí)間。
?1
#include?<stdio.h>
?2
#include?<stdlib.h>
?3
?4
int?main(void)
?5

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