为什么我的程序不可以运行阿,各位大哥大姐帮忙找找
#include<string.h>#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#define N 3
#define ST struct student
struct student
{
char name[20];
int age;
struct student *next;
};
ST *creat(int n)
{
ST *h,*p,*s;
for(int i=0;i<N;i++)
{
s=(ST *)malloc(sizeof(ST));
printf("please input name and age\n");
scanf("%s%d",&s->name,&s->age);
if(i==0)
p=h=s;
else
p->next=s;
s->next=NULL;
p=s;
}
return(h);
}
ST *search(ST *h,char *n)
{
ST *p;
char *m;
p=h->next;
while(p!=NULL)
{
m=p->name;
if(strcmp(m,n)==0)
return(p);
else p=p->next;
}
if(p==NULL)
/*
while(p->name!=n&&p->next!=NULL)
p=p->next;
if(p->name==n) return(p);
if(p->name!=n&&p->next==NULL)*/
printf("node %d has not been found!\n",n);
}
ST *search2(ST *h,char *x)
{
ST *p,*s;
char *y;
p=h->next;
s=h;
while(p!=NULL)
{
y=p->name;
if(strcmp(y,x)==0)
return(s);
else
{
p=p->next;
s=s->next;
}
}
if(p==NULL)
printf("没有查到该数据! ");
}
void insert(ST *p)
{
char stuname[20];
ST *s;
if((s=(ST *)malloc(sizeof(ST)))==NULL)
{
printf("不能分配空间!");
exit(0);
}
printf("please input name and age:");
scanf("%s%d",stuname,&s->age);
strcpy(s->name,stuname);
s->next=p->next;
p->next=s;
}
void del(ST *x,ST *y)
{
ST *s;
s=y;
x->next=y->next;
free(s);
}
void print(ST *h)
{
ST *p;
p=h->next;
printf("数据信息为:\n");
while(p!=NULL)
{
printf("姓名:%s\t年龄:%d\n",p->name,p->age);
p=p->next;
}
p=p->next;
}
void quit()
{
exit(0);
}
void menu(void)
{
printf("\t\t\t 单链表c语言实现实例\n\n");
printf("\t\t\t\t++++++++++++++++++++\n");
printf("\t\t\t+ [1] 建 立 新 表 +\n");
printf("\t\t\t+ [2] 插 入 数 据 +\n");
printf("\t\t\t+ [3] 删 除 数 据 +\n");
printf("\t\t\t+ [4] 打 印 数 据 +\n");
printf("\t\t\t+ [5] 退 出 +\n");
printf("\t\t\t+ 未建立新表,请先建立 +\n");
printf("\t\t\t+ + + + + + + + + + + + +\n");
printf("\t\t\t 输入你的选项(1-5):");
}
void main()
{
int choose;
ST *head,*searchpoint,*forepoint;
char fullname[20];
while(1)
{
menu();
scanf("%d",&choose);
switch(choose)
{
case 1:head=creat(N);
break;
case 2: printf("输入你要在哪个人后面插入:");
scanf("%s",fullname);
searchpoint=search(head,fullname);
printf("你所查找的人的姓名为:%s",*&searchpoint->name);
insert(searchpoint);
print(head);
printf("\n按回车键回到主菜单。");
getchar();getchar();
break;
case 3:print(head);
printf("\n输入你所要删除的人的姓名:");
scanf("%s",fullname);
searchpoint=search(head,fullname);
forepoint=search2(head,fullname);
del(forepoint,searchpoint);
break;
case 4:print(head);
printf("\n按回车键回到主菜单。");
getchar();getchar();
break;
case 5:quit();
break;
default:printf("你输入了非法字符!按回车键回到主菜单。");
menu();
getchar();
}
}
}