网页资讯视频图片知道文库贴吧地图采购
进入贴吧全吧搜索

 
 
 
日一二三四五六
       
       
       
       
       
       

签到排名:今日本吧第个签到,

本吧因你更精彩,明天继续来努力!

本吧签到人数:0

一键签到
成为超级会员,使用一键签到
一键签到
本月漏签0次!
0
成为超级会员,赠送8张补签卡
如何使用?
点击日历上漏签日期,即可进行补签。
连续签到:天  累计签到:天
0
超级会员单次开通12个月以上,赠送连续签到卡3张
使用连续签到卡
01月29日漏签0天
c语言吧 关注:801,845贴子:4,375,901
  • 看贴

  • 图片

  • 吧主推荐

  • 视频

  • 游戏

  • 4回复贴,共1页
<<返回c语言吧
>0< 加载中...

大神求解,我做的信息表最后的switch语句出错,帮忙指导改正一下

  • 只看楼主
  • 收藏

  • 回复
  • 镜花_明镜止水
  • 毛蛋
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define LEN sizeof(struct student)
struct student
{
long num;
char name[20];
int score;
struct student*next;
};
struct student*creat();
void display(struct student*head);
struct student*insert(struct student*head,struct student*newp);
struct student*deletep(struct student*head,long num);
choose();
void main()
{
struct student*creat();
void display(struct student*head);
printf("the menu choose:1 inset 2 delete 3 print");
choose();
}
int count=0;
struct student*creat()
{
struct student*head=NULL,*newp,*tail;
newp=tail=(struct student*)malloc(LEN);
printf("please input the data:\n");
scanf("%ld%s%d",&newp->num,newp->name,&newp->score);
while(newp->num!=0)
{
count++;
if(count==1)
head=newp;
else
tail->next=newp;
tail=newp;
newp=(struct student*)malloc(LEN);
scanf("%ld%s%d",&newp->num,newp->name,&newp->score);
}
tail->next=NULL;
return(head);
}
void display(struct student*head)
{
struct student*p=head;
while(p!=NULL)
{
printf("%ld\t%s\t%d\n",p->num,p->name,p->score);
p=p->next;
}
}
struct student*insert(struct student*head,struct student*newp)
{
struct student*p,*q;
p=q=head;
if(head==NULL)
{
head=newp;
newp->next=NULL;
}
else
{
while((newp->num>p->num)&&(p->num!=NULL))
{
q=p;
p=p->next;
}
if(newp->num<=p->num)
{
newp->next=p;
if(head==p)
head=newp;
else
q->next=newp;
}
else
{
p->next=newp;
newp->next=NULL;
}
}
count++;
return(head);
}
struct student*deletep(struct student*head,long num)
{
struct student*p,*q;
p=q=head;
while(p->num!=num&&p->next!=NULL)
{
q=p;
p=p->next;
}
if(p->num==num)
{
if(p==head)
head=p->next;
else
q->next=p->next;
free(p);
count--;
}
else
printf("%ld cannot found\n",num);
return(head);
}
choose()
{
int i;
pirnf("your choice");
scanf("%d",&i);
switch(i)
{
case 1 :
struct student*insert(struct student*head,struct student*newp);
break;
case 2 :
struct student*deletep(struct student*head,long num);
break;
case 3 :void display(struct student*head);
break;
}
}
求大神帮忙改一下最后的choose()函数


  • 镜花_明镜止水
  • 毛蛋
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
求解啊。。。


2026-01-29 06:25:29
广告
不感兴趣
开通SVIP免广告
  • 镜花_明镜止水
  • 毛蛋
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
有没有人


  • 镜花_明镜止水
  • 毛蛋
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define LEN sizeof(struct student)
struct student
{
long num;
char name[20];
int score;
struct student*next;
};
struct student*creat();
void display(struct student*head);
struct student*insert(struct student*head,struct student*newp);
struct student*deletep(struct student*head,long num);
choose();
void average(struct student*head);
void main()
{
struct student*creat();
void display(struct student*head);
printf("the menu choose:1 inset 2 delete 3 print");
choose();
average(struct student*creat);
}
int count=0;
struct student*creat()
{
struct student*head=NULL,*newp,*tail;
newp=tail=(struct student*)malloc(LEN);
printf("please input the data:\n");
scanf("%ld%s%d",&newp->num,newp->name,&newp->score);
while(newp->num!=0)
{
count++;
if(count==1)
head=newp;
else
tail->next=newp;
tail=newp;
newp=(struct student*)malloc(LEN);
scanf("%ld%s%d",&newp->num,newp->name,&newp->score);
}
tail->next=NULL;
return(head);
}
void display(struct student*head)
{
struct student*p=head;
while(p!=NULL)
{
printf("%ld\t%s\t%d\n",p->num,p->name,p->score);
p=p->next;
}
}
struct student*insert(struct student*head,struct student*newp)
{
struct student*p,*q;
p=q=head;
if(head==NULL)
{
head=newp;
newp->next=NULL;
}
else
{
while((newp->num>p->num)&&(p->num!=NULL))
{
q=p;
p=p->next;
}
if(newp->num<=p->num)
{
newp->next=p;
if(head==p)
head=newp;
else
q->next=newp;
}
else
{
p->next=newp;
newp->next=NULL;
}
}
count++;
return(head);
}
struct student*deletep(struct student*head,long num)
{
struct student*p,*q;
p=q=head;
while(p->num!=num&&p->next!=NULL)
{
q=p;
p=p->next;
}
if(p->num==num)
{
if(p==head)
head=p->next;
else
q->next=p->next;
free(p);
count--;
}
else
printf("%ld cannot found\n",num);
return(head);
}
choose()
{
int i;
pirnf("your choice");
scanf("%d",&i);
switch(i)
{
case 1 :
struct student*insert(struct student*head,struct student*newp);
break;
case 2 :
struct student*deletep(struct student*head,long num);
break;
case 3 :void display(struct student*head);
break;
}
}
void average(struct student*head)
{
int sum=0;
int ave=0;
int n;
struct student*p;
p=head;
while(p->next!=NULL)
sum=sum+p->num;
printf("the number of date\n");
scanf("%d",&n);
ave=sum/n;
printf("%d",&ave);
}


登录百度账号

扫二维码下载贴吧客户端

下载贴吧APP
看高清直播、视频!
  • 贴吧页面意见反馈
  • 违规贴吧举报反馈通道
  • 贴吧违规信息处理公示
  • 4回复贴,共1页
<<返回c语言吧
分享到:
©2026 Baidu贴吧协议|隐私政策|吧主制度|意见反馈|网络谣言警示