http://tech.sina.com.cn/i/c/2002-05-17/115781.shtml aslkjflk
http://sms.sina.com.cn/ringtone/ringtone.shtml asdjf
http://news.sina.com.cn/z/pl/index.shtml>faslk;dj
http://news.sina.com.cn/c/2003-12-22/14112438916.shtmlaf
asdf
asdf
fdasf asdf
dasf
asf dsaf
dasf dsaf asdf asdf
====================
对如上所示的名为trim.txt的文本文件进行如下操作,本意是想找出其中所有URL,但老是出现“读不能读的内存”的错误,为了查出问题,就改成如下:
void CTrimDlg::OnButtonTrim()
{
//TODO: Add your control notification handler code here
FILE *pFile, *pTemFile;
pFile = fopen("g:\\trim.txt", "rb");
fseek(pFile, 0, SEEK_END);
int nLen = ftell(pFile) + 1;
char *str = new char[nLen];
char *strT, *pResult1, *pResult2;
char ch;
memset(str, 0, nLen);
fseek(pFile, 0, SEEK_SET);
fread(str, sizeof(char), nLen, pFile);
pTemFile = fopen("g:\\after_trim.txt", "ab");
strT = str;
pResult1 = strstr(strT, "http://");
pResult2 = strstr(strT, ".shtml");
while (pResult1 != pResult2)
{
ch = *pResult1;
fputc(ch, pTemFile);
pResult1++;
}
fputs(".shtml\r\n", pTemFile);
strT = pResult2;//不加此行可正常写入两个相同URL。
//加此行就出错,但不加此行
//怎么用循环来找出所有URL啊。请高手分析分析!
pResult1 = strstr(strT, "http://");
pResult2 = strstr(strT, ".shtml");
while (pResult1 != pResult2)
{
ch = *pResult1;
fputc(ch, pTemFile);
pResult1++;
}
fputs(".shtml\r\n", pTemFile);
fflush(pTemFile);
fclose(pTemFile);
fclose(pFile);
delete str;
}
◆◆
评论读取中....
请登录后再发表评论!
◆◆
修改失败,请稍后尝试