c语言程序还未输入数据程序就结束
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c语言程序还未输入数据程序就结束相关的知识,希望对你有一定的参考价值。
为什么我的程序到输入TF的地方直接就结束了,输入不了Goon值?
#include<stdio.h>
#include<stdlib.h>
static int Max=0;
typedef struct Node
char Aod;
int Time,placeNum,Num;
node;
node *base,*top,*front,*rear,*front1,*rear1;
void Init()
printf("请输入停车场最大泊车量:");
scanf("%d",&Max);
base = (node*)malloc(Max*sizeof(Node));
top = base;
for(int i=1;i<=Max;i++)
top->placeNum = i;
top++;
top = base;
front1 = (node*)malloc(2*Max*sizeof(Node));
rear1 = front1;
front = (node*)malloc(2*Max*sizeof(Node));
rear = front;
void Input()
char Goon = 'T';
while(Goon == 'T')
int time = rear1->Time,num = rear1->Num;
char aod = rear1->Aod;
printf("请分别输入汽车车辆信息:\n(“到达”或“离去”信息、汽车牌照号码以及到达或离去的时刻)");
scanf("%c%s%d",&aod,&num,&time);
rear1++;
printf("是否继续输入车辆信息(T/F):");
scanf("%c",&Goon);
void Set()
int i=0;
if(rear1->Aod == 'A')
if(int((top-base)/sizeof(Node)) < Max)
top->Time = rear1->Time;
top->Num = rear1->Num;
top->Aod = rear1->Aod;
top++;
rear1++;
else
rear->Time = rear1->Time;
rear->Num = rear1->Num;
rear->Aod = rear1->Aod;
rear++;
rear1++;
else
node *t=base;
while(t!=top)
t++;
if(t->Num == rear1->Num)
int PN = t->placeNum;
printf("%d号位的车辆已离开",PN);
while(++t) --t = ++t;//t至于队尾
t->placeNum = PN;
rear1++;
break;
if(++t)
rear1->Time = rear->Time;
rear1->Num = rear->Num;
rear1->Aod = rear->Aod;
rear++;
rear1++;
void Put()
if(rear->Aod == 'A')
if(int((top-base)/sizeof(Node)) < Max)
top->Time = rear->Time;
top->Num = rear->Num;
top->Aod = rear->Aod;
top++;
rear++;
else
node *t=base;
while(t!=top)
t++;
if(t->Num == rear->Num)
int PN = t->placeNum;
printf("%d号位的车辆已离开",PN);
while(++t) --t = ++t;//t至于队尾
t->placeNum = PN;
rear++;
break;
void main()
Init();
Input();
while(++rear1) Set();
while(++rear) Put();
#include <stdlib.h>
static int Max = 0;
typedef struct Node
char Aod;
int Time, placeNum, Num;
node;
node *base, *top, *front, *rear, *front1, *rear1;
void Init()
printf("请输入停车场最大泊车量:");
scanf("%d", &Max);
base = (node *)malloc(Max * sizeof(Node));//1
top = base;
for (int i = 1; i <= Max; i++)
top->placeNum = i;
top++;
top = base;
front1 = (node *)malloc(2 * Max * sizeof(Node));//2
rear1 = front1;
front = (node *)malloc(2 * Max * sizeof(Node));//3
rear = front;
void Input()
char Goon = 'T';
while (Goon == 'T')
int time = rear1->Time, num = rear1->Num;
char aod = rear1->Aod;
printf("请分别输入汽车车辆信息:\\n(“到达”或“离去”信息、汽车牌照号码以及到达或离去的时刻)");
scanf("%c%s%d", &aod, &num, &time);//类型不匹配
rear1++;
printf("是否继续输入车辆信息(T/F):");
scanf("%c", &Goon);
void Set()
int i = 0;
if (rear1->Aod == 'A')
if (int((top - base) / sizeof(Node)) < Max)//4
top->Time = rear1->Time;
top->Num = rear1->Num;
top->Aod = rear1->Aod;
top++;
rear1++;
else
rear->Time = rear1->Time;
rear->Num = rear1->Num;
rear->Aod = rear1->Aod;
rear++;
rear1++;
else
node *t = base;
while (t != top)
t++;
if (t->Num == rear1->Num)
int PN = t->placeNum;
printf("%d号位的车辆已离开", PN);
while (++t)
--t = ++t; //t至于队尾
t->placeNum = PN;
rear1++;
break;
if (++t)
rear1->Time = rear->Time;
rear1->Num = rear->Num;
rear1->Aod = rear->Aod;
rear++;
rear1++;
void Put()
if (rear->Aod == 'A')
if (int((top - base) / sizeof(Node)) < Max)//5
top->Time = rear->Time;
top->Num = rear->Num;
top->Aod = rear->Aod;
top++;
rear++;
else
node *t = base;
while (t != top)
t++;
if (t->Num == rear->Num)
int PN = t->placeNum;
printf("%d号位的车辆已离开", PN);
while (++t)
--t = ++t; //t至于队尾
t->placeNum = PN;
rear++;
break;
void main()
Init();
Input();
while (++rear1)
Set();
while (++rear)
Put();
//这代码不忍直视 参考技术A 代码不全不清楚什么情况,如果你是用scanf之类的建议在输入完之后清下输入缓冲区(代码自行百度),不然容易出现下一个输入直接被跳过(其实是直接取了上次的输入)的情况。
ZZNUOJ_用C语言编写程序实现1371:无重复的排序(附完整源码)
题目描述
输入一组整型数据,每个数据都大于0且小于100,输入遇0时结束。要求将输入的数排序,并去掉相同的数,将排序结果从小到大输出。
输入
输入只有一组数据,输入数据不超过20个,输入0表示输入结束,0不作为有效数据。 所有输入都在正确的范围内。
输出
输出排序后的数据,每个数据占一行。
样例输入
16 89 9 8 6 16 9 0
样例输出
6
8
9
16
89
完整源码:
#include<stdio.h>
#
以上是关于c语言程序还未输入数据程序就结束的主要内容,如果未能解决你的问题,请参考以下文章