- 论坛徽章:
- 0
|
先谢谢两位兄弟,代码如下,请帮忙看看。file文件存在 并能read数据。
等下我把数组再放大点试试
char fileCon[10000] = {0};
int fd = open("/home/file", O_RDONLY);
int num = read(fd, fileCon, sizeof(fileCon));
char title[400] ={0};
while( true )
{
string a = fileCon;
int indexStart = a.find("test.php?id=", 0);
char buf[400]={0};
if((indexEnd<0) || (indexStart<0))
{
break;
}
a.copy(buf, indexEnd-indexStart, indexStart);
//get title
indexStart = a.find(">", indexStart);
indexEnd = a.find("</a>", indexStart);
if( 4<(indexEnd - indexStart)&& (indexEnd - indexStart)<50 )
{
a.copy(title, indexEnd-indexStart-1, indexStart+1);
cout << buf << endl;
cout << title << endl;
memset(title, '\0', sizeof(title));
memset(buf, '\0', sizeof(buf));
memset(fileCon, '\0', sizeof(fileCon));
a.copy(fileCon, a.length()-indexEnd, indexEnd);
}else
{
memset(fileCon, '\0', sizeof(fileCon));
a.copy(fileCon, a.length()-indexEnd, indexEnd);
memset(title, '\0', sizeof(title));
memset(buf, '\0', sizeof(buf));
}
}
如果这个文件大运行一会后才会异常退出。
所以调试很难,所以上来问问,谢谢
[ 本帖最后由 h0tr0ck 于 2007-6-21 13:10 编辑 ] |
|