weixin_39724080 2019-06-11 19:30 采纳率: 50%
浏览 899
已结题

数据结构 输入以后程序自动结束 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;
}

图片说明

  • 写回答

6条回答 默认 最新

  • Nikola desian 2019-06-11 20:31
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 全志H618ROM新增分区
  • ¥20 jupyter保存图像功能的实现
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况