有个问题请教高手:
谁有空,帮我看一下:运行: case '1':
h=creat(i);break;
h=creat(i);调用返回出错;谢了
出错图看附加压缩文件。。。。
、、、、、、、、、、代码如下
#include "hh.h"
#include "creat.h"
#include "find.h"
#include "display.h"
#include "del.h"
#include "order.h"
int display(int i,Infor *head);
Infor *order(int i,Infor *head) ;
Infor *search(int x,Infor*head);
Infor *del(int i,Infor *head);
Infor *creat(int i);
char choice;
Infor *h;
static int i=0;
int main()
{
do
{
system("cls");
printf("\n※※※※※※※※※※※※※※※※※ Welcome! ※※※※※※※※※※※※※※※※\n\n\n");
printf("\t\t1. Add the information.\n"
"\t\t2. Display the information.\n"
"\t\t3. Search the althlete's/horse's information.\n"
"\t\t4. The order to playact.\n"
"\t\t5. Delete the information.\n"
"\t\t6. Exit.\n\n\n");
fflush(stdin);
printf("\t●Please input your choice: ");
scanf("%c",&choice);
switch(choice)
{
case '1':
h=creat(i);break;
case '2':
display(i,h);break;
case '3':
h=search_main(i,h);break;
case '4':
h=del(i,h);break;
case '5':
h=del(i,h);break;
case '6':
printf("\n\n※※※※※※※※※※※※※※※※※ Goodbye! ※※※※※※※※※※※※※※※※※\n"); break;
}
getchar(); //暂停一次
while(h)
{
free(h);
h=h->next;
}//将内存释放
}while(choice!='6');/*菜单结束选择条件*/
return 0;
}
creat.h文件:
#ifndef CREAT_H_INCLUDED
#define CREAT_H_INCLUDED
#include "hh.h"
Infor *creat(int i)
{
char a;
int len_1,len_2,d,e;
Infor*pr,*r,*head;//建立头head,尾r,pr为移动节点;
head=(Infor *)malloc(sizeof(Infor));
head->next=NULL;
r=head;
do
{
pr=(Infor *)malloc(sizeof(Infor));//申请新节点内存
if(pr==NULL)
{
printf("\n\n\t◆No memory!");
return(NULL);
}
printf("\n\t★There has been %d massages!\n\n",i);
printf("\t●Please input the %dth athletes' information here.\n",i+1);
do
{
fflush(stdin);
printf("\n\tThe serial number includes 6 numbers.\n"
"\tAnd if inputing error, it will get back!!!\t\n");
printf("\t●Input the serial number of athlete : ");
scanf("%d",&(pr->id));
}while(pr->id>999999||pr->id<100000) ;//限制为六位数
fflush(stdin);
printf("\n\t●Please input the name: ");
gets(pr->name);
len_1=strlen(pr->name);
for(d=0;d<len_1;d++)
{
if(pr->name[d]<65||pr->name[d]>122||(pr->name[d]>90&&pr->name[d]<97))//限制为字母输入
{
printf("\n\t◆Input error! Number is not allowded in the name!\n\tPlease input again.");
printf("\n\t●Please input the name: ");
gets(pr->name);
len_1=strlen(pr->name);
d=0;
}
}
do
{
printf("\n\tAlthelete's age is between 14-90"
"\n\tIf imput error,it will get back!!!");
fflush(stdin);
printf("\n\t●Age: ");
scanf("%d",&(pr->age));
}while(pr->age<14||pr->age>90); //控制年龄
fflush(stdin);
printf("\n\t●Country: ");
gets(pr->country);
len_2=strlen(pr->country);
for(e=0;e<len_2;e++)
{
if(pr->country[e]<65||pr->country[e]>122||(pr->country[e]>90&&pr->country[e]<97))
{
printf("\n\t◆Input error! Number is not allowded in the country!\n\tPlease input again.");
printf("\n\t●Please input the country: ");
gets(pr->country);
len_2=strlen(pr->country);
}
}
do
{
fflush(stdin);
printf("\n\t●The serial number of horse includes 6 numbers."
"\n\tAnd if inputing error, it will get back!!!)\t\n");
printf("\n\t●The horse's serial number: ");
scanf("%d",&(pr->horse_number));
}while((pr->horse_number)>999999||pr->horse_number<100000);
do
{
fflush(stdin);
printf("\n\n\tThe horse's age is between 2-40"
"\n\tIf imput error,it will get back!!!");
printf("\n\t●The horse's age: ");
scanf("%d",&(pr->horse_age));
}while(pr->horse_age<2||pr->horse_age>40);
pr->next=NULL;
r->next=pr;
r=r->next;//r指向下一个节点位置
i++;//计数器
printf("\n\t●Do you want to input input the information of another one?(Y\\N) ");
fflush(stdin);
a=getchar();
}while(a=='y'||a=='Y'&&i<N);//限制数据条数在100条以内,可以通过改变宏来调节
pr->next=NULL;
return (head);
}
#endif // CREAT_H_INCLUDED