标题:下面是一个C语言程序,但是有点错误,请大侠指教。
只看楼主
qiuyuting
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2011-6-15
结帖率:0
已结贴  问题点数:20 回复次数:2 
下面是一个C语言程序,但是有点错误,请大侠指教。
#define NULL 0
#define LEN sizeof(struct customer)
#include "string.h"
struct customer
{
int num;
char name[20];
long date;
struct customer *next;
}cus;
struct customer *creat(void)
{
struct customer *head,*p1,*p2;
int n=0;
p1=(struct customer *)malloc(LEN);
p2=(struct customer *)malloc(LEN);
printf("qing shu ru ke hu de xin xi:\n");
printf("\nfang jian:");
scanf("%d",&p1->num);
printf("\n");
printf("xing ming:");
scanf("%s",p1->name);
printf("\n");
printf("ru zhu shi jian:");
scanf("%ld",&p1->date);
printf("\n");
head=NULL;
while(p1->num!=0)
{
n++;
if(n==1)
head=p1;
else
p2->next=p1;
p2=p1;
p1=(struct customer *)malloc(LEN);
printf("qing shu ru ke hu de xin xi:\n");
printf("\nfang jian:");
scanf("%d",&p1->num);
printf("\n");
printf("xing ming:");
scanf("%s",p1->name);
printf("\n");
printf("ru zhu shi jian:");
scanf("%ld",&p1->date);
printf("\n");
}
p2->next=NULL;
return(head);
}
struct customer *insert(struct customer *head,struct customer *consumer)
{
struct customer *p1,*p2;
p1=head;
p2=consumer;
if(p1->next!=NULL)
p1=p1->next;
if(p1->next==NULL)
{
p1->next=p2;
p2->next=NULL;
}
return(head);
}
struct customer *del(struct customer *head,int num)
{
struct customer *p1,*p2;
if(head==NULL)
{
printf("mei you ke hu xin xi\n");
return(head);
}
p1=head;
while(num!=p1->num&&p1->next!=NULL)
{
p2=p1;p1=p1->next;
}
if(num==p1->num)
{
if(p1==head)
head=p1->next;
else
p2->next=p1->next;
printf("tui fang xin xi:\n");
printf("kefang:%d\n",&p1->num);
printf("xing ming:%s\n",p1->name);
printf("ru zhu shi jian:%ld\n",&p1->date);
}
else
printf("mei you gai ke hu de xin xi\n");
return(head);
}
struct customer *search(struct customer *head,char c_name[])
{
struct customer *p;
p=head;
while(strcmp(p->name,c_name)&&p->next!=NULL)
p=p->next;
if(p->name==c_name)
{
printf("gai ke hu de xin xi wei:\n");
printf("fang jian:%d\nxing ming:%S\nru zhu shi jian:%ld",p->num,p->name,p->date);
}
if(p->name!=c_name&&p->next==NULL)
printf("mei you gai ke hu xin xi!\n");
}
void print(struct customer *head)
{
struct customer *p;
printf("\nxian you ke hu xin xi wei:\n");
p=head;
if(head!=NULL)
do
{
printf("ke fang:%d\n",p->num);
printf("xing ming:%s\n",p->name);
printf("ru zhu shi jian:%ld\n",p->date);
p=p->next;
}while(p!=NULL);
}
main()
{
struct customer *head,*p;
int m,number;
char c_name[20];
printf("\n");
printf(" *************************************************\n");
printf(" huan ying jin ru bin guan ke fang guan li xi tong\n");
printf(" *************************************************\n");
printf(" *************************************************\n\n");
printf(" 1:jian ku\n");
printf(" 2:deng ji\n");
printf(" 3:tui fang\n");
printf(" 4:cha xun\n");
printf(" *************************************************\n\n");
printf("zhi xing chao zuo:\n");
scanf("%d",&m);
if(m==1)
head=creat();
else
if(m==2)
{
printf("qing shu ru yao deng ji de ke hu xin xi:");
p=(struct customer *)malloc(LEN);
scanf("%d %s %ld",&p->num,p->name,&p->date);
head=insert(head,p);
print(head);
}
else
if(m==3)
{
printf("qing shu ru yao tui fang ke hu de fang jian hao:");
scanf("%d",&number);
head=del(head,number);
print(head);
}

else
if(m==4)
{
printf("qing shu ru yao cha xun ke hu de xing ming:");
scanf("%s",c_name);
search(head,c_name);
}
else
printf("zhi xing chao zuo cuo wu!");
}

宾馆客房管理软件
软件目标:
(1)某宾馆有301、302、303、304、305五个标准间,每个标准间可住2人;
(2)链表存储结构:姓名、性别、房号、后续指针,按房间号有序;
(3)能实现入住(注意性别)和退房,能按给定姓名、房号查询;

问题:
在开始的结构体
struct customer
{
int num;
char name[20];
long date;
struct customer *next;
}cus;
中加入性别,安排入住的时区分性别,而且这个代码中感觉房号的设计有点问题,如果运行是从房间1开始输入房客的信息而不是从301开始,
这个程序每个房间只能住一个人,希望能改成两个人。
帮忙改一下,谢谢。

搜索更多相关主题的帖子: C语言 xing jian long qing 
2011-06-15 12:19
bccn_2012
Rank: 6Rank: 6
等 级:侠之大者
帖 子:158
专家分:447
注 册:2011-5-14
得分:20 
读这样的代码好痛苦。。。
能不能注意一下代码 的格式啊!!!
2011-06-15 12:40
qiuyuting
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2011-6-15
得分:0 
回复 2楼 bccn_2012
额。。。辛苦了
2011-06-15 12:41



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-342931-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015097 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved