首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

又一个小疑点的

2012-03-20 
又一个小问题的求助#includeiostream.hstruct student{char *namedouble score}int foud(struct stud

又一个小问题的求助
#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 名字没有显示出来,为什么啊

[解决办法]

C/C++ code
p->name++;//罪魁祸首
[解决办法]
字符串比较请用strcmp。而不是直接比较指针的地址。

热点排行