求大神指教。帮忙运行一下看看错误在哪,怎么改正

Rookiekk Rookiekk 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
#include<stdio.h>
#include<string.h>
#include<malloc.h>
#define ESC 0x1b
struct node
{
char name[20];
int num;
char sex;
int age;
float score[10];
struct node *next;
};
struct node *head,*tail;
void init_ht()
{
head=NULL;
tail=NULL;
}
struct node *p;
void put(p)
struct node *p;
{
p->next=NULL;
if(head==NULL)
head=p;
else
tail->next=p;
tail=p;
}
void input_data()
{
int i;
char ch;
struct node *p;
while(1)
{
printf("input data(Y/N):");
ch=getchar();
if(ch=='y'||ch=='Y')
{
p=(struct node *)(malloc(sizeof(struct node)));
printf("input name:");
scanf("s%",&p->name);
printf("input sum:");
scanf("%d",&p->num);
printf("input sex:");
scanf("%c",&p->sex);
printf("input age:");
scanf("%d",&p->age);
printf("input 10 score:");
for(i=0;i<10;i++)
scanf("%f",&p->score[i]);
put(p);

}
else
break;
}
}

void FDname()
{
int i;
char name[20];
struct node *p;
printf("input name:");
scanf("%s",name);
p=head;
while(p!=NULL)
{
if(strcmp(name,p->name)==0)
{
printf("Name=%s\n",p->name);
printf("Num=%d\n",p->num);
printf("Sex=%c\n",p->sex);
printf("Age=%d\n",p->age);
for(i=0;i<10;i++)
printf("Score=%d",p->score[i]);
}
p=p->next;

}
}
void FDnum()
{
int i,snum;
struct node *p;
printf("input num:");
scanf("%d",&snum);
p=head;
while(p!=NULL)
{
if(snum==p->num)
{
printf("Name=%s\n",p->name);
printf("Num=%d\n",p->num);
printf("Sex=%c\n",p->sex);
printf("Age=%d\n",p->age);
for(i=0;i<10;i++)
printf("Score=%d",p->score[i]);
}
p=p->next;
}
}
void find_data()
{
char ch;
while(1)
{
printf("1:Find by name\n");
printf("2:Find by num\n");
printf("ESC:Exit\n");
ch=getchar();
switch(ch)
{
case'1':
FDname();
break;
case'2':
FDnum();
break;
case'ESC':
return;
}
}
}
main()
{
init_ht();
input_data();
find_data();
}
...全文
评论 5
收藏 已收藏
分享
返回顶部
Rookiekk
C语言 70,039 成员 243,237 内容