打开文件;
while(文件未结束)
{
char* p = 读一行;
int count = 字段个数;
while(count > 0)
{
CString str = "";
while(*p !=(空格或Tab))
{
str += *p++;
}//现在str中已经读出一个字段,其它的就Imitate吧
count--;
……
}
}
关闭文件;
while(文件未结束)
{
char* p = 读一行;
int count = 字段个数;
while(count > 0)
{
CString str = "";
while(*p !=(空格或Tab))
{
str += *p++;
}//现在str中已经读出一个字段,其它的就Imitate吧
count--;
……
}
}
关闭文件;
这么快啊,先谢啦!我试试先
还有在吗?
你写的:char* p=读一行;
是用什么方法读出一行啊?
CArchive ar(&file,CArchive::load);
ar.Serialize();
CString line;
while(ar.ReadString(line))
{……
}
//不知道有没有语法错误,如有请多多包涵
我想实现的功能如题:就是将某目录下所有文本文件格式化成自己的格式的数据程序开始正常,转了几个文件后老是提示:
First-chance exception in convert.exe (KERNEL32.DLL): 0xC0000005: Access Violation.
是不是我用的那个数组有问题啊?麻烦各位高手帮帮忙
源代码如下:
void FormatData(LPCTSTR lpszFileName)
{
CString line[600]; //用于保存文本文件中的每一行
CFile src,dst;
src.Open(lpszFileName,CFile::modeRead);
dst.Open("format.txt",CFile::modeWrite);
int num=1; //行号
CArchive ar(&src,CArchive::load);
while(ar.ReadString(line[num]))
{
num++;
} //.........对数据的格式化处理 dst.Close();
ar.Close();
src.Close();
}调用如下:WIN32_FIND_DATA FindFileData;
CString path="";
HANDLE hFind=NULL;
hFind=FindFirstFile("*.txt",&FindFileData);
if(hFind==INVALID_HANDLE_VALUE)
{
MessageBox("没有找到文件");
return;
}
path.Format("d:\\data\\%s",FindFileData.cFileName);
FormatData(path);
while(FALSE!=FindNextFile(hFind,&FindFileData))
{ path.Format("d:\\data\\%s",FindFileData.cFileName);
FormatData(path);
}
By the way,//.........对数据的格式化处理 干吗不放在循环里呢,读一行处理一行,也就用不着CString数组了
我放在数组里是因为这样我比较方便格式化呀我调试过了提示arccore.cpp 461行不行了,对应的源代码是在CArchive::Abort()里的,我想是跟CArchive有关,但不知具体原因出在哪里?昨晚还没睡觉呢,现在要先回去,等下午再来
FILE *fp;
fp=fopen("path\filename","rwb..");
fgets(fp,buf,size);//读一行,放在buf里
fputs(fp,buf,size);//写一行
读出的buf爱怎么处理就怎么处理