这个程序,在我输入以后就自动结束,然后工作台直接关闭了,连“我并不觉得”都没有输出,请问出了什么问题呢?我找到问题是出在截图中的scanf那里,就这一行输入之后几秒就结束运行了,麻烦大家看看我为什么输入错误了,以及怎么输入才行?
#include <stdio.h>
#include <stdlib.h>
#define SIZE 100
#define STACKINCREAMENT 10
typedef int Status;
typedef struct{
int *base;
int *top;
int stacksize;
}Sqstack;
Sqstack InitStack(){
Sqstack s;
s.base=(int *)malloc(sizeof(int)*SIZE);
if(!s.base) exit(0);
s.top=s.base;
s.stacksize=SIZE;
return s;
}
Sqstack Push(Sqstack s, int e){
if(s.top-s.base>=s.stacksize){
s.base=(int *)realloc(s.base,(s.stacksize+STACKINCREAMENT)*sizeof(int));
if(!s.base) exit (0);
s.top=s.base+s.stacksize;
s.stacksize+=STACKINCREAMENT;
}
*(s.top)=e;
s.top++;
return s;
}
int GetTop(Sqstack s){
int e;
if(s.top==s.base) return 0;
e=*(s.top-1);
return e;
}
Sqstack Pop(Sqstack s){
if(s.top==s.base) return s;
s.top--;
return s;
}
int main(){
char *input;
char a;
int i,j,k,e,error1=0,error2=0,t;
i=j=k=0;
Sqstack s,r;
s=InitStack();
r=InitStack();
printf("请输入你要检测的字符串。#结束\n");
fflush(stdin);scanf("%s",input);printf("%s",input);getchar();
printf("我并不觉得!\n");
while(*input!='#'){
printf("今天天气好!\n");
s.top=s.base;
error1=0;
error2=0;
i=j=k=0;
t=0;
a=*(input+t);
while(a!='\0'){
switch(a){
printf("你是傻逼吧!\n");
case '(':
s=Push(s,1);
i++;
break;
printf("嘿嘿嘿嘿嘿!\n");
case '[':
s=Push(s,2);
j++;
break;
case '{':
s=Push(s,3);
k++;
break;
case ')':
e=GetTop(s);
if(e!=1) error1++;
else {
i--;
if(i>0) error2++;
s=Pop(s);
}
break;
case ']':
e=GetTop(s);
if(e!=2) error1++;
else {
j--;
if(i>0||j>0) error2++;
s=Pop(s);
}
break;
case '}':
e=GetTop(s);
if(e!=3) error1++;
else {
k--;
if(i>0||j>0||k>0) error2++;
s=Pop(s);
}
break;
default:break;
}//switch
t++;
a=*(input+t);
printf("哈哈哈哈哈!\n");
}//while a
if(error1||s.top!=s.base) printf("不匹配!\n");
else {
printf("正常\n");
if(error2>0) printf("不匹配\n");
else printf("正常\n");
}
printf("请输入你要检测的字符串。#结束\n");
fflush(stdin);scanf("%s",input);getchar();
}//while input
return 0;
}