就是程序运行完后再按任意一个键他就停止运行了,如何让它再按一个回车键,他就回到开头,重新运行呢
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<malloc.h>
#define MAXSIZE 100
typedef struct
{
char shu[10];
int num;
}Num;
typedef Num ElemType;
typedef struct
{
ElemType *data;
int length;
}SeqList;
void InitList(SeqList L) /顺序表的创建/
{
L->data=(ElemType)malloc(sizeof(ElemType)*MAXSIZE);
if(!L->data)
exit(0);
L->length=0;
}
void input(ElemType *e) /*输入字符信息 */
{
printf("输入单个字符\n");
scanf("%s",&e->shu);
printf("请输入该字符的值\n");
scanf("%d",&e->num);
}
void output(ElemType *e) /输出字符信息/
{
printf("字符:%s 字符值:%d \n",e->shu,e->num);
}
int InsElem(SeqList *L,int i,ElemType e) /*插入元素函数 */
{
int j;
if(L->length>=MAXSIZE)
{
printf("顺序表已满!");
return -1;
}
if(i<1||i>L->length)
{
printf("插入位置出错!");
return 0;
}
for(j=L->length-1;j>=i-1;j--)
L->data[j+1]=L->data[j];
L->data[i-1]=e;
L->length++;
return 1;
}
void trans(char *exp,char *postexp,SeqList *L) /将中缀表达式转换成后缀表达式函数/
/中缀表达式为输入表达式/
{
struct {
char data[MAXSIZE];
int top;
}op; /运算符栈/
int i=0;
op.top=-1;
int j;
char x[10];
char l;
while(*exp!='#') /*表达式没有结束时 */
{
switch(*exp)
{
case '(':
op.top++;op.data[op.top]=exp;
exp++;
break;
case ')':
while(op.data[op.top]!='(')
{
postexp[i++]=op.data[op.top];
op.top--;
}
op.top--;
exp++;
break;
case '+':
case '-':
while(op.top!=-1&&op.data[op.top]!='(')
{
postexp[i++]=op.data[op.top];
op.top--;
}
op.top++;
op.data[op.top]=exp;
exp++;
break;
case '':
case '/':
while(op.data[op.top]==''||op.data[op.top]=='/')
{
postexp[i++]=op.data[op.top];
op.top--;
}
op.top++;
op.data[op.top]=*exp;
exp++;
break;
// case '':break;
default:
strcpy(x,&(*exp));
char xls=x[0];
while((*exp>='A'&&*exp<='Z')||(*exp>='a'&&exp<='z'))/*类型的转换 */
{
for(int count=0;countlength;count++)
{
if(xls==(L->data[count].shu))
{
j=L->data[count].num;
break;
}
else
continue;
}
*exp=((char)j+48);
postexp[i++]=*exp;
exp++;
}
while(*exp>='0'&&*exp<='9')
{
postexp[i++]=*exp;
exp++;
}
postexp[i++]='#';
break;
}
}
while(op.top!=-1)
{
postexp[i++]=op.data[op.top];
op.top--;
}
postexp[i]='\0';
}
float compvalue(char *postexp) /根据后缀表达式求值函数/
{
struct {
float data[MAXSIZE];
int top;
}st; /定义了数栈/
float a,b,c,d;
st.top=-1;
printf("在这里");
while(postexp!='\0')
{
switch(postexp)
{
case '+':
a=st.data[st.top];
st.top--;
b=st.data[st.top];
st.top--;
c=a+b;
st.top++;
st.data[st.top]=c;
break;
case '-':
a=st.data[st.top];
st.top--;
b=st.data[st.top];
st.top--;
c=b-a;
st.top++;
st.data[st.top]=c;
break;
case '':
a=st.data[st.top];
st.top--;
b=st.data[st.top];
st.top--;
c=ba;
st.top++;
st.data[st.top]=c;
break;
case '/':
a=st.data[st.top];
st.top--;
b=st.data[st.top];
st.top--;
if(a!=0)
{
c=b/a;
st.top++;
st.data[st.top]=c;
}
else
printf("除零错误\n");
break;
default:
d=0;
while(*postexp>='0'&&postexp<='9')
{
d=10d+*postexp-'0';
postexp++;
}
st.top++;
st.data[st.top]=d;
break;
}
postexp++;
}
return st.data[st.top];
}
int main()
{
while(1)
{
int i,j,n,len;
SeqList L;
ElemType e;
char exp[MAXSIZE],postexp[MAXSIZE];
char *k;
InitList(&L);/*建立表*/
printf("请输入需要建立的字符数量(小于100)\n");
scanf("%d",&len);
for(i=0;i<len;i++)
{
printf("第%d个字符:\n",i+1);
input(&L.data[i]);
}
L.length=len;
putchar('\n');
for(i=0;i<L.length;i++) /*输出所有字符信息*/
{
output(&L.data[i]);
}
putchar('\n');
printf("请输入表达式,以#结束\n");
scanf("%s",&exp);
trans(exp,postexp,&L);
printf("表达式的值为:%.2lf\n",compvalue(postexp));
char ch=getchar();
if(ch=='\n')
system("cls");
continue;
exit(0);
}
}