求大神指教。帮忙运行一下看看错误在哪,怎么改正
#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();
}
#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();
}
...全文
相关推荐
全站仪设站错误内业改正程序设计
全站仪设站错误内业改正程序设计是测绘领域中一项关键的技术,它涉及到测量数据的精确处理和分析。
c++宝贵错误与改正
运行时错误运行时错误在编译阶段无法发现,只有在程序运行时才会暴露。例如,除以零、数组越界、空指针引用等。使用条件语句和异常处理机制(如`try-catch`)能有效预防和处理这些错误。### 4.
不懂的工程代码,求指教
【标题】:“不懂的工程代码,求指教”在编程领域,遇到不理解或出错的工程代码是很常见的。这通常需要我们具备分析问题、调试代码以及查阅文档的能力。
初学C语言编程易犯的错误及其改正
初学C语言编程易犯的错误及其改正
卫星钟差改正
这一效应必须在钟差改正中考虑,否则会导致定位错误。6. **连续监测与更新**:钟差并非恒定不变,会受到环境因素(如温度变化)和卫星硬件老化的影响。因此,钟差改正模型需要不断更新以保持准确性。


