小问题请教各位
#include<iostream.h>
#include<string.h>
void main()
{
struct stu
{
char num[10];
stu *next;
};
stu *head,*ps,*pend;
head=NULL;
ps=new stu;
cin>>ps->num;
pend=ps;
while(ps->num!="a")
{
if(head=NULL)
{
head=ps;
}
else
{
pend->next=ps;
pend=ps;
}
cin>>ps->num;
}
pend->next=NULL;
delete ps;
}
我想输入一组字符串.
在输入a后结束.
可是我用上面的代码无法实现,跳不出来.
各位谁有办法??
问题点数:20、回复次数:5Top
1 楼iamcaicainiao(老菜,长征)回复于 2006-03-30 10:42:40 得分 0
!=Top
2 楼iamcaicainiao(老菜,长征)回复于 2006-03-30 10:45:19 得分 10
while (strcmp(ps->num, "a")!=0)Top
3 楼yinqing_yx(淘汰引擎)(玩虚一族)回复于 2006-03-30 10:51:14 得分 0
if(head=NULL)??????赋值~Top
4 楼ugg(逸学堂(exuetang.net))回复于 2006-03-30 14:05:15 得分 10
while(ps->num!="a")
~~~~~~~~
char[]数组没有重载=号操作,这两这不能对比。
修改方法
1:
struct stu
{
char num[10]; // 把这里声明为string num;
stu *next;
};
2:
while (ps->num[0]!='a')Top
5 楼iamwiner(烛泪)回复于 2006-03-30 15:20:18 得分 0
基础知识不过关呵Top




