又一个小问题的求助
#include<iostream.h>
struct student
{
char *name;
double score;
};
int foud(struct student *,char *);
void main()
{ int a,i;
struct student data[3]={{"asd",98},{"yui",97},{"zxc",96}};
char *p="zxc";
for(i=0;i<3;i++)
{
a=foud(&data[i],p);
if(a==1)
cout << data[i].name << ":" << data[i].score;
}
}
int foud(struct student *p,char *p1)
{
while(*p->name!='\0'&&*p1!='\0')
{
if(*p->name!=*p1)
return 0;
else
{
p->name++;
p1++;
}
}
return 1;
}
做书上的练习题,要求按名字查找分数,但是上面这个程序执行后,返回的分数正常,但是名字却不能显示,上面这个的运行结果为 :96 名字没有显示出来,为什么啊
[解决办法]
p->name++;//罪魁祸首
[解决办法]
字符串比较请用strcmp。而不是直接比较指针的地址。