/*只适用于txt,vbe,c,cpp等文件*/
#include <cstdlib>
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
void fengeming(void);
void wenjiangeshu(void);
void fengewenjian(void);
char srwenjianming[100] = {'/0'};
char b[500] = {'/0'},fengewjm[50] = {'/0'}, zifu;
int geshu, i,zifugeshu = 0, j = 1, zifugeshu2;
ifstream wcin1,wcin2;
ofstream wout;
int main(int argc, char *argv[])
{
char no;
do
{
cout << "请输入您要分割的文件名:";
cin >> srwenjianming;
cout << "您输入的文件名是:" << srwenjianming << endl << endl;
cout << "请确认输入是否正确,错误请输入N/n。/n";
cin >> no;
}while(no == 'N' || no == 'n');
wcin1.open(srwenjianming);
if(wcin1.fail())
{
cout << "链接" << srwenjianming << "失败!/n/n";
cout << "可能原因有:/n";
cout << "1.文件名输入错误,请查看输入是否正确!/n";
cout << "2.请确定" << srwenjianming << "是否和此程序在同一个文件夹下!/n/n";
system("PAUSE");
exit(1);
}
cout << "您想把文件分割成几份?/n/n";
while(1)
{
cin >> geshu;//b
if ( geshu > 0 && geshu < 10)
break;
cout << "您输入的有误,请从新输入!/n/n";
}
wenjiangeshu();
while(wcin1.get(zifu))
{
zifugeshu += 1;
}
zifugeshu2 = zifugeshu / geshu;
wcin1.close();
wcin2.open(srwenjianming);
fengeming();
fengewenjian();
wcin2.close();
cout << "文件分割成功,谢谢您的使用,再见!/n/n";
system("PAUSE");
return EXIT_SUCCESS;
}
void fengeming()
{
for (i = 0; srwenjianming[i] != '/0'; i++)
{
if (srwenjianming[i] == '.')
{
fengewjm[i] = '(';
fengewjm[i+1] = b[j];
fengewjm[i+2] = ')';
for (; srwenjianming[i] != '/0' ; i++)
{
fengewjm[i+3] = srwenjianming[i] ;
}
break;
}
fengewjm[i] = srwenjianming[i];
}
j += 1;
return;
}
void wenjiangeshu()
{
for (i = 0; i <= geshu; i++)
{
b[i] = i+48;
}
return;
}
void fengewenjian()
{
while(geshu)
{
wout.open(fengewjm);
if (wout.fail())
{
cout << "抱歉!/n出现未知错误,请重试!/n/n";
system("PAUSE");
exit(1);
}
for (zifugeshu = zifugeshu2 ; zifugeshu > 0; zifugeshu--)
{
wcin2.get(zifu);
wout << zifu;
}
wout.close();
geshu -= 1;
fengeming();
}
return;
}
/*欢迎大家指点批评!!!!!!!!*/