帮个忙,为什么这函数不能循环进行??

lxhtzy 2006-07-27 05:10:31
struct student
{char num[15];
char name[20];
char sex;
int sorce[5];
struct student *next;};

struct student *bulid(void)
{struct student stu,*head,*p1,*p2;char a[15]={"ok"};
head=NULL;n=0;
p2=p1=(struct student *)malloc(LX);
{printf("Input the number:\nnum=");
scanf("%s",p1->num);
printf("Input the name:\nname:");
scanf("%s",p1->name);
printf("Input the sex:\nsex:");
getchar();p1->sex=getchar();
printf("Input the sorce:\nsorce=");
scanf("%s",p1->sorce); }
while(n<6);
{n=n+1;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;
p1=(struct student *)malloc(LX);
{printf("Input the number:\nnum=");
scanf("%s",p1->num);
printf("Input the name:\nname:");
scanf("%s",p1->name);
printf("Input the sex:\nsex:");
getchar();p1->sex=getchar();
printf("Input the sorce:\nsorce=");
scanf("%s",p1->sorce);} }
p2->next=NULL;
return head;}
为什么????
下面这个可以???
struct stu
{long num;
float sorce;
struct stu *next;}*head,*p1,*p2;
int n;
struct stu *creat(void)
{
n=0;
p1=p2=(struct stu *)malloc(sizeof(struct stu));
scanf("%ld,%f",&p1->num,&p1->sorce);
head=0;
while(p1->num!=0)
{n=n+1;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;p1=(struct stu *)malloc(sizeof(struct stu));
scanf("%ld,%f",&p1->num,&p2->sorce);}p2->next=0;
return head; }
...全文
145 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
gongyuan 2006-07-27
  • 打赏
  • 举报
回复
用flushall();清空缓冲区也可以。
m_nNightmire 2006-07-27
  • 打赏
  • 举报
回复
while(n<6);

去掉分号

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧