程序不知道哪有问题,请帮忙找下
注:代码用Vc++6.0正常运行,但PRINT函数部分内容不能显示在屏幕中,谁能告诉我原因#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <io.h>
#include <string.h>
#include <time.h>
#define MAX 10
#define price 0.01
typedef struct time{
int hour;
int min;
}Time;
typedef struct node{
char num[20];
Time reach;
Time leave;
}CarNode;
typedef struct NODE{
CarNode *stack[MAX+1];
int top;
}SeqStackCar;
typedef struct car{
CarNode *data;
struct car *next;
}QueueNode;
typedef struct Node{
QueueNode *head;
QueueNode *rear;
}LinkQueueCar;
void InitStack(SeqStackCar*);
int InitQueue(LinkQueueCar*);
int Arrival(SeqStackCar*,LinkQueueCar*);
void Leave(SeqStackCar *,SeqStackCar *,LinkQueueCar *);
void PRINT(CarNode *p,int);
void List(SeqStackCar,LinkQueueCar);
void List1(SeqStackCar *);
void List2(LinkQueueCar *);
void main(){
SeqStackCar Enter,Temp;
LinkQueueCar Wait;
int ch;
InitStack(&Enter);
InitStack(&Temp);
InitQueue(&Wait);
while(1){
printf("欢迎使用停车管理系统\n");
printf("1.车辆到达\n");
printf("2.车辆离开\n");
printf("3.返回\n");
printf("输入所需服务:\n");
while(1){
scanf("%d",&ch);
if(ch>=1&&ch<=4) break;
else printf("输入错误!重新选择:\n");
}
switch(ch){
case 1:Arrival(&Enter,&Wait);break;
case 2:Leave(&Enter,&Temp,&Wait);break;
case 3:List(Enter,Wait);break;
case 4:exit(0);
default: break;}
}
}
void InitStack(SeqStackCar *s){
int i;
s->top=0;
for(i=0;i<20;i++){
s->stack[s->top]=NULL;
}
}
int InitQueue(LinkQueueCar *Q){
Q->head=(QueueNode *)malloc(sizeof(QueueNode));
if(Q->head!=NULL){
Q->head->next=NULL;
Q->rear=Q->head;
return(1);
}
else return(-1);
}
int Arrival(SeqStackCar *Enter,LinkQueueCar *w){
CarNode *p;
QueueNode *t;
p=(CarNode *)malloc(sizeof(CarNode));
flushall();
printf("输入车牌号码:\n");
gets(p->num);
if(Enter->top<MAX){
Enter->top++;
printf("该车在第%d号位\n",Enter->top);
printf("该车进入停车场的时间\n");
scanf("%d:%d",&(p->reach.hour),&(p->reach.min));
while(p->reach.hour<0||p->reach.hour>23||p->reach.min<0||p->reach.min>59){
printf("输入时间错误,重新输入:\n");
scanf("%d:%d",&(p->reach.hour),&(p->reach.min));
}
Enter->stack[Enter->top]=p;
return(1);}
else
{
printf("停车场已满\n");
t=(QueueNode *)malloc(sizeof(QueueNode));
t->data=p;
t->next=NULL;
w->rear->next=t;
w->rear=t;
return(1);
}
}
void Leave(SeqStackCar *Enter,SeqStackCar *Temp,LinkQueueCar *w)
{
int room;
CarNode *p,*t;
QueueNode *q;
if(Enter->top>0){
printf("输入车在停车场位置(1-%d):\n",Enter->top);
while(1){
scanf("%d",&room);
if(room>=1&&room<=Enter->top)
break;
else printf("错误!请重选:");
}
while(Enter->top>room){
Temp->top++;
Temp->stack[Temp->top]=Enter->stack[Enter->top];
Enter->stack[Enter->top]=NULL;
Enter->top--;
}
p=Enter->stack[Enter->top];
Enter->stack[Enter->top]=NULL;
Enter->top--;
while(Temp->top>=1){
Enter->top++;
Enter->stack[Enter->top]=Temp->stack[Temp->top];
Enter->stack[Enter->top]=NULL;
Temp->top--;
}
PRINT(p,room);
if((w->head!=w->rear)&&(Enter->top<MAX)){
q=w->head->next;
t=q->data;
Enter->top++;
printf("候车场的%d号车进入第%d号位置!\n",t->num,Enter->top);
printf("输入到达时间:\n");
scanf("%d:%d",&(t->reach.hour),&(t->reach.min));
w->head->next=q->next;
if(q==w->rear) w->rear=w->head;
Enter->stack[Enter->top]=t;
free(q);
}
else printf("候车场没有车\n");}
else printf("停车场没有车\n");
}
void PRINT(CarNode *p,int room){
int A1,A2,B1,B2;
int a,b,c,d;
printf("请输入离开时间:\n");
scanf("%d:%d",&(p->leave.hour),&(p->leave.min));
while(p->leave.hour<0||p->leave.hour>23){
printf("输入错误!\n");
printf("请重新输入离开时间:\n");
scanf("%d%d",&p->leave.hour,&p->leave.min);
}
if(0<(p->leave.min)&&(p->leave.min)<59){
if(p->reach.hour<p->leave.hour){
printf("离开车辆的车牌号:\n");
puts(p->num);
printf("其到达时间为:%d:%d\n",p->reach.hour,p->reach.min);
printf("其离开时间为:%d:%d\n",p->leave.hour,p->leave.min);
A1=p->reach.hour;
A2=p->reach.min;
B1=p->leave.hour;
B2=p->leave.min;
a=B2-A2;
b=B1+A1;
if(a>0){
printf("该车应交费用为:%4.2f元!\n",(((b-1)*60+a)+1)*price);
free(p);}
else{
printf("该车应交费用为:%4.2f元!\n",(((b*60+a)+1)*price));
free(p);}
}
else{
printf("离开车辆的车牌号:\n");
puts(p->num);
printf("其到达时间为:%d:%d\n",p->reach.hour,p->reach.min);
printf("其离开时间为:%d:%d\n",p->leave.hour,p->leave.min);
A1=p->reach.hour;
A2=p->reach.min;
B1=p->leave.hour;
B2=p->leave.min;
c=B1-A1;
d=B2-A2;
if(d<0){
printf("该车应交费用为:%4.2f元!\n",(((c-1)*60+(-d))+1)*price);
free(p);}
else{
printf("该车应交费用为:%4.2f元!\n",(((c*60+d)+1)*price));
free(p);}}
}
}
void List1(SeqStackCar *S){
printf("你选的是停车场停车情况!\n");
int i;
if(S->top>0){
printf("\n位置 到达时间 车牌号\n");
for(i=1;i<=S->top;i++){
printf("%d%d:%d\n",i,S->stack[i]->reach.hour,S->stack[i]->reach.min);
puts(S->stack[i]->num); }
}
else printf("停车场里没有车!\n");
}
void List2(LinkQueueCar *W){
printf("你选择的是候车场停车情况!\n");
QueueNode *p;
p=W->head->next;
if(W->head!=W->rear){
printf("等待车辆车牌号为:\n");
while(p!=NULL){
printf("%d%c\n",p->data->num);
p=p->next;
}
}
else printf("便道里没有车!\n");
}
void List(SeqStackCar S,LinkQueueCar W){
int flag,tag;
flag=1;
while(flag)
{
printf("**********查看**********\n");
printf("1.车库 2.便道 3.返回\n");
printf("************************\n");
printf("请选择(1-3):[ ]\b\b");
while(1)
{
scanf("%d",&tag);
if(tag>=1&&tag<=3) break;
else printf("错误!请重选(1-3):[ ]\b\b");
}
switch(tag)
{
case 1:List1(&S);break;/*列表显示车库信息*/
case 2:List2(&W);break; /*列表显示便到信息*/
case 3:flag=0;break;
default: break;
}
}
}