#include<stdio.h>
#include<stdlib.h>
struct student
{ char name[20];
long num;
int age;
char sex;
float score;
struct student *next;
};
struct student *head,*this,*new;
main()
{ void listall(void);
void new_record(void);
char ch;
int flag=1;
head=NULL;
while(flag==1)
{
printf("\ntype'E'or'e'to enter new record,");
printf("type'L'or'l'to list all record:");
ch=getchar();
getchar();
switch(ch)
{
case'e':
case'E':new_record();break;
case'l':
case'L':listall();break;
default:flag=0;
}
}
getch();
}
void new_record(void)
{
char numstr[20];
new=(struct student *)malloc(sizeof(struct student));
if(head==NULL)
head=new;
else
{
this=head;
if(this->next!=NULL)
this=this->next;
else
this->next=new;
}
this=new;
printf("\nenter name:");
gets(this->name);
printf("\n enter numstr:");
gets(numstr);
this->num=atol(numstr);
printf("\nenter age:");
gets(numstr);
this->age=atoi(numstr);
printf("\nenter sex:");
this->sex=getchar(); getchar();
printf("\nenter float:");
get(numstr);
this->score=atof(numstr);
this->next=NULL;
}
void listall(void)
{
int i=0;
if(head==NULL)
{
printf("\nempty list.\n");
return;
};
this=head;
do {
printf("\nrecord number %d\n",++i);
printf("name:%s\n",this->num);
printf("num:%ld\n",this->num);
printf("age:%d\n",this->age);
printf("sex:%c\n",this->sex);
printf("score:%6.2f\n",this->score);
this=this->next;
}
while(this!=NULL);
}
请帮忙改一哈!
答案:1 悬赏:20 手机版
解决时间 2021-05-05 04:14
- 提问者网友:饥饿走向夜
- 2021-05-04 15:08
最佳答案
- 五星知识达人网友:長槍戰八方
- 2021-05-04 15:23
是例题吗?
去掉不必要的分号,把函数定义放在MAIN前面,还有什么下面补充
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯