数据结构表达式树,怎么让每个表达式均以“#”开始,以“#”结束

这是main

 #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "stack.h"


int main(void){
    int i,j,len,cnt;
    OPTR *st=(OPTR*)malloc(sizeof(OPTR));//栈的初始化 
    EXPT *nst=(EXPT*)malloc(sizeof(EXPT));//栈的初始化 
    char str[85];
    char out[85];//后缀输出?
    printf("请输入一个表达式\n"); 
    scanf("%s",str);//中序输入表达式 
    nst->top=-1;
    st->top=-1;
    cnt=0;
    len=strlen(str);//求字符串的长度 
    for(i=0;i<len;i++){
        if(isnumber(str[i]))
            out[cnt++]=str[i];
        else{
            if(str[i]=='('||isempty(st)){
                push(st,str[i]);
                continue;
            }
            if(str[i]==')'){
                while(top(st)!='('){
                    out[cnt++]=top(st);
                    pop(st);
                }
                pop(st);
                continue;
            }
            while(!isempty(st)&&top(st)!='('&&priority(str[i])<=priority(top(st))){
                out[cnt++]=top(st);
                pop(st);
            }
            push(st,str[i]);//把不是数字的字符入栈 
        }
    }
    //如果栈不为空,把栈里的内容放到Out数组 
    while(!isempty(st)){
        out[cnt++]=top(st);
        pop(st);
    }
    out[cnt]='\0';
    for(i=0;i<cnt;++i)
        printf("%c ",out[i]);
    printf("\n");
    for(i=0;i<cnt;i++){
        if(isnumber(out[i])){
            npush(nst,out[i]);
            continue;
        }else if(out[i]=='+'){
            nst->data[nst->top-1]+=ntop(nst);
            npop(nst);
        }else if(out[i]=='-'){
            nst->data[nst->top-1]-=ntop(nst);
            npop(nst);
        }else if(out[i]=='*'){
            nst->data[nst->top-1]*=ntop(nst);
            npop(nst);
        }else if(out[i]=='/'){
            nst->data[nst->top-1]/=ntop(nst);
            npop(nst);
        }
        for(j=0;j<=nst->top;++j)
            printf("%d ",nst->data[j]);
        for(j=i+1;j<cnt;++j)
            printf("%c ",out[j]);
        printf("\n");

    }
    return 0;
}

这是stack

 typedef struct{
    char data[85];
    int top;
}OPTR;
typedef struct{
    int data[85];
    int top;
}EXPT;
// 判断用户输入是否是数字 
bool isnumber(char ch){
    if(ch>='0'&&ch<='9')
        return true;
    else
        return false;
}
//判断栈是否为空 
bool isempty(OPTR *s){
    if(s->top==-1)
        return true;
    else
        return false;
}
//入栈
void push(OPTR *s,char ch){
    s->data[++s->top]=ch;
}
void npush(EXPT *s,char ch){
    s->data[++s->top]=ch-'0';
}
//出栈 
char pop(OPTR *s){
    return s->data[s->top--];
}
int npop(EXPT *s){
    return s->data[s->top--];
}
//优先级定义 
int priority(char ch){
    if(ch=='(')
        return 0;
    if(ch=='+'||ch=='-')
        return 1;
    if(ch=='*'||ch=='/')
        return 2;

    return 0;
}
//得到栈顶元素 
char top(OPTR *s){
   return s->data[s->top];
}
//得到栈顶元素 
int ntop(EXPT *s){
    return s->data[s->top];
}

要加一个新功能就是每个表达式要用#开头,#号结束,求大佬写出完整代码啊

不知是不是这个意思,我改了一下你看看:

 int main(void){
    int i, j, len, cnt;
    OPTR *st = (OPTR*)malloc(sizeof(OPTR));//栈的初始化 
    EXPT *nst = (EXPT*)malloc(sizeof(EXPT));//栈的初始化 
    char str[85];
    char out[85];//后缀输出?
    printf("请输入一个表达式\n");
    scanf("%s", str);//中序输入表达式 
    nst->top = -1;
    st->top = -1;
    cnt = 0;
    len = strlen(str);//求字符串的长度 
    char szTemp[256] = { 0 };
    memcpy(szTemp, str + 1, len - 2);//将头尾的#去掉
    char *ptr;
    ptr = strtok(szTemp, "#");
    i = 1;
    while (ptr != NULL) {
        printf("表达式%d:%s\n", i, ptr);
        i++;
        ptr = strtok(NULL, "#");
    }

图片说明

不是很明确你的意思,是说你的输入改成可以同时计算多个表达式,而每个表达式之间用#分割,比如
12+2#3*5+7#
这样,然后输出
14
22

是这个意思么?
那么最简单的是,scanf得到输入后用strtok切分下。

额,不是,不用分割表达式。就是简单的输入#表达式#

那么是这个意思吗:

    char str[85];
    char out[85];//后缀输出?

    printf("请输入一个表达式\n");
    scanf("%s", str);//中序输入表达式 
    int len = strlen(str);
    if (str[0] == '#' &&str[len - 1] == '#')
    {
        printf("中序遍历\n");
        break;
    }
    else
    {
        printf("其他操作\n");
    }