哪个大神可以解答链表的问题?
程序代码: 这个程序在VC6.0中能运行,但是第二次进入input函数就运行不了,数据不能加入链表中。求解
还有用身份证号(18位)进行查询时,也运行不了,但用2、3位数字或是10位数字又能运行了,没有语法上的错误,但就是查询不到。求大神解答啊!!!!#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define NULL 0
#define LEN sizeof(struct client)
struct client
{
char name[20];
char sex[2];
char age[3];
char id[18];
char tel[11];
char indate[6];
char outdate[6];
char room[3];
struct client *next;
};
static struct client *head;
void menu(); /*选择菜单*/
void input(struct client *head); /*增加租客*/
void search(struct client *head); /*查询租客*/
void main()
{
int choose,k=1;
extern struct client *head;
head=(struct client *)malloc(LEN);
head->next=NULL;
while(k)
{
menu(); /*选择菜单*/
scanf("%d",&choose);system("cls");
switch(choose)
{
case 1:input(head);break; /*增加租客*/
case 2:search(head);break; /*查询租客*/
case 8:k=0;break; /*退出系统*/
}
}
}
void menu()
{
printf("\n +++++++++++++++菜单+++++++++++++++++\n");
printf(" + 1.增加租客 +\n");
printf(" + 2.查询租客 +\n");
printf(" + 8.退出系统 +\n");
printf(" ++++++++++++++++++++++++++++++++++++\n");
printf(" 请选择功能: ");
}
void input(struct client *head)
{
int x=1;
struct client *p,*p1;
while(x)
{
p1=(struct client *)malloc(LEN);
printf(">>>现在填写租客个人信息<<<\n");
printf(" 请输入租客姓名:");scanf("%s",&p1->name);
printf(" 请输入租客性别:");scanf("%s",&p1->sex);
printf(" 请输入租客年龄:");scanf("%s",&p1->age);
printf(" 请输入租客身份证号:");scanf("%s",&p1->id);
printf(" 请输入租客电话号码:");scanf("%s",&p1->tel);
printf(">>>现在填写租客租住信息:(日期按XXXXXX填写)<<<\n");
printf(" 请输入租客入住时间:");scanf("%s",&p1->indate);
printf(" 请输入租客退租日期:");scanf("%s",&p1->outdate);
printf(" 请输入租客房间号:");scanf("%s",&p1->room);
if(head->next==NULL) { head->next=p1; p=p1; }
else { p->next=p1; p=p1; p1->next=NULL; }
printf("\n +++++继续输入请按1 停止输入请按0+++++ \n");
scanf("%d",&x);
}
system("cls");return ;
}
void search(struct client *head)
{
char a[20];
struct client *p;
p=head->next;
if(p==NULL)
{
printf("\n***还没有输入任何租客信息,请输入后再查询!***\n\n");
return ;
}
printf("请输入需要查询的租客的身份证号:");scanf("%s",a);
while(strcmp(a,p->id)!=0) p=p->next;
printf(" 1.姓名:%s\n",p->name);
printf(" 2.性别:%s\n",p->sex);
printf(" 3.年龄:%s\n",p->age);
printf(" 4.身份证号:%s\n",p->id);
printf(" 5.电话号码:%s\n",p->tel);
printf(" 6.房间号:%s\n",p->room);
printf(" 7.入住时间:%s\n",p->indate);
printf(" 8.退租日期:%s\n",p->outdate);
}









