求帮助啊 不知道哪里错了

C语言 码拜 8年前 (2016-04-22) 867次浏览
小白做一个简单的车库管理系统
头文件
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR -1
#define INPEASIBLE -1
#define MAXNUM 2//车库容量
#define price 3//每小时费用
typedef struct time
{
int hour;
int min;
}time1;
//定义时间
typedef struct carlist
{
char num[10];
time1 arrive;
time1 leave;
}carlist;
//定义车辆信息
typedef struct carstation
{
carlist *station[MAXNUM+1];
int top;
}carstation;//定义车库
//初始化车库
void stationinit(carstation s)
{
int i;
s.top=0;
for(i=0;i<=MAXNUM;i++)
{
s.station[i]=NULL;
}
}
//车辆到达
int Arrive(carstation *s)
{
carlist *p;
s=(carstation *)malloc(sizeof(carstation));
p=(carlist *)malloc(sizeof(carlist));
printf(“请输入车牌号,例如赣A1234:”);
scanf(“%s”,p->num);
if(s->top<MAXNUM)
{
s->top++;
scanf(“车停在第%d个位置”,s->top);
printf(“请输入到达时间:/**:**/”);
scanf(“%d:%d”,(p->arrive.hour),&(p->arrive.min));
s->station[s->top]=p;
return OK;
}
}
//判断车库能否为空
int empty(carstation s)
{
return(s.station==0 ?1:0);
}
//查找车辆位置
int find(carstation s,carlist m,char carnum[])
{
int i;
if(empty(s))
{
printf(“车库是空的,无车辆停放!\n”);
exit(1);
}
else
while(strcmp(m.num,carnum))
{
i++;
}
if(i>=s.top)
{
printf(“车库不存在这辆车!\n”);
exit(1);
}
return(i<s.top ?i:-1);
}
//车辆离开
void Leave(carstation *s,int position)
{
int i;
if(s->top==0)
printf(“车库为空!\n”);
if(position<0||position>=s->top)
{
printf(“车库不存在这辆车!\n”);
}
for(i=position;i<s->top-1;i++)
{
s->station[i]=s->station[i+1];
s->top–;
}
}
//打印离开车辆信息
void display(carlist *p,int position)
{
int H1,H2,M1,M2,T;
printf(“请输入车辆离开时间:/**:**/”);
scanf(“%d:%d”,(p->leave.hour),&(p->leave.min));
printf(“离开的车辆的车牌号为:”);
puts(p->num);
H1=p->arrive.hour;
H2=p->leave.hour;
M1=p->arrive.min;
M2=p->leave.min;
T=H2-H1+(M2-M1);
if(p->arrive.min>0&&p->leave.min)
{
p->arrive.hour++;
p->leave.hour++;
printf(“应付的费用为:%2.f”,T*price);
free(p);
}
}
主文件(目前卡在这没有继续往下做)
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#include “head.h”
void main()
{
int a,b;
char carnum[10];
time1 ly;
carlist ll;
carstation fhh;
stationinit(fhh);
a=Arrive(&fhh);
b=find(fhh,ll,carnum);
}
运行输入时间以后就终止程序了 VC++6.00环境
解决方案

10

void stationinit(carstation s)
改成
void stationinit(carstation &s)

30

是基础没学好还是怎么的,乱写的么
仔细看看代码
void stationinit(carstation s) 这个参数是什么,s.top=0; 看你里面怎么用的
定义一个 carstation fhh;这样定义,fhh已经有存储空间了, Arrive(carstation *s) 里面,你又去申请空间,是个什么鬼

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明求帮助啊 不知道哪里错了
喜欢 (0)
[1034331897@qq.com]
分享 (0)