- 论坛徽章:
- 0
|
FILE *fp1;
if ((fp1=fopen("c.txt","r"))==NULL)
{
cout<<"\nCould not open the file."<<endl;
cout<<"Exiting program."<<endl;
exit(1);
}
int stri=0;
char *ch;
char *strs;
while (!feof(fp1))
{
if ((fgets(strs,256,fp1)) != NULL)
{
if (strstr(strs,ch) != NULL)
{
int a;
for (a=0;a<stri;a++)
cout << strdata[a];
cout << "**************************";
stri=0;
strcpy(*strdata,"");
}
else
{
strdata[stri] = strs;
stri++;
//cout << strdata[stri-1] << stri ;
}
}
}
fclose(fp1);
这段代码是一个查找文本文件代码中的一段,在这段中查找到要应的内容后就显示在数组strdata[]中存储的一段内容,但是这段代码用指针有错误,数组中全是最后读取的值,需要怎么修改才能完成呢????? |
|