为了账号安全,请及时绑定邮箱和手机立即绑定

动态链表,怎么才能改成像课本上的可以输入输出多次,

动态链表,怎么才能改成像课本上的可以输入输出多次,

溯源1 2017-01-16 12:06:56
#include "stdio.h"#include<malloc.h>#include<string.h>#define LEN sizeof(struct student)struct student{int num;int score;struct student*next;};struct student*create(){    char ch;    struct student *head;    struct student*p1,*p2;    int a=0;    printf("是否输入新数据:(y/n)");    while(toupper(ch=getche())=='Y');//这个不是要输入输出y多次,输入输出多个num,score,直到ch不等于y,但是为什么只有输入输出一次    {    p1=(struct student*)malloc(LEN);    printf("\n请输入:");    scanf("%d%d",&p1->num,&p1->score);    printf("是否输入新数据:(y/n)");    a++;    if(a==1) head=p1;    else p2->next=p1;    p2=p1;    p1->next=NULL;    }    return(head);}void print(struct student *head){struct student *p;p=head;while(p!=NULL){printf("\n学号:%d,成绩:%d",p->num,p->score);p=p->next;}}void main( ){struct student *stu;stu=create();print(stu);}
查看完整描述

1 回答

已采纳
?
望远

TA贡献1017条经验 获得超1032个赞

while(toupper(ch=getche())=='Y');//这个不是要输入输出y多次,输入输出多个num,score,
//结尾处多了个;循环是空循环体。


查看完整回答
1 反对 回复 2017-01-16
  • 溯源1
    溯源1
    学霸看下原问题,还有个小问题,不过可以运行
  • 溯源1
    溯源1
    我加了个图片在在原问题
  • 望远
    望远
    获取一个字符的函数不是getchar()吗?
点击展开后面7
  • 1 回答
  • 0 关注
  • 1431 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信