请大家帮我看看问题何在?
//这时一个简单的文件处理小工具,功能是输入一个文本文件,
//经处理后删掉逗号,句号,和制表符代之以空格。
//但是有问题。
//我的编译环境是VC6.0。
#include <iostream>
#include <fstream>
using namespace std;
char* getDir(char *filepath)
{
char *dir;
char *temp;
char *fileName = strrchr(filepath, '\\');
int dirLen=strlen(filepath)-strlen(fileName)+1;
temp=dir=new char[dirLen+1];
for(int i=0;i<dirLen;i++)
*temp++=*filepath++;
*temp='\0';
return dir;
}
bool creatZipedFile(char *agv[])
{
ifstream infile(agv[1]);
if(!infile)
{
cerr<<"Can't open "<<agv[1]<<endl;
cin.get();
return false;
}
ofstream outfile;
char *ZipedFilePath = getDir(agv[0]);
strcat(ZipedFilePath,"ZipedFile.cpp");
cout<<ZipedFilePath<<endl;
outfile.open(ZipedFilePath);
if(!outfile)
{
cerr<<"Can't creat ZipedFile "<<ZipedFilePath<<endl;
cin.get();
return false;
}
char word;
bool space=false;
while(infile>>word)
{
while(word==','||word=='.'||word=='\t')
//这里我并没有删除回车,回车符怎么也不见了?
{
infile>>word;
space = true;
}
if(space)
{
outfile<<' ';
space=false;
}
outfile<<word;
}
cout<<"success!"<<endl;
infile.close();
outfile.close();
delete[] ZipedFilePath;
return true;
}
void main(int agr, char *agv[])
{
if(agr<2)
{
cerr<<"Parameters Error!"<<endl
<<"It needs two parameters."<<endl
<<"First is the source file name"<<endl
<<"and the second is the dest file name."<<endl
<<"Press any key to quit"<<endl;
}
else if(!creatZipedFile(agv))
{
cerr<<"There's something wrong when processing."<<endl
<<"Please contact to the author:"<<endl
<<"Meter@mail.biti.edu.cn"<<endl;
}
cout<<"Bye!";//程序还没到这里就报错了,为什么?
}