数据结构 输入以后程序自动结束 scanf

这个程序,在我输入以后就自动结束,然后工作台直接关闭了,连“我并不觉得”都没有输出,请问出了什么问题呢?我找到问题是出在截图中的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;
}

图片说明

scanf("%s",input),需要&

可以在试一下,有时候是电脑出bug,xp输入的格式错了,scanf(%,)

代码没有贴对,没法帮你看
修改你的问题,用“代码片”功能格式化下你的代码

要这样写' scanf("%s",&input) ',input前面加&

图片说明

楼上说的对,你造了个指针,指针是干啥的?指向内存,然后内存才会存储数据呀。通过移动指针,访问数据。

你是直接想把指针指向数据,你指到哪里的数据呢?

才看到你还有个求助做法。
你使用数组来存,char *inpute 改成 char inpute[] = {}
这种,改指针为数组,就把数据放到这个数组中了,然后你再去操作。