windows在**.exe中触发了一个断点,其原因可能是堆被损坏,这说明dll中有bug
#include "D:\touwenjian\consts.h"
#define MAXNUM 100
typedef char DataType;
#include "D:\touwenjian\seqstack.h"
#include "D:\touwenjian\seqstack.c"
int InfixtoSuffix(char * infix, char * suffix) /*转换表达式顺序,输出*/
{
/*将中缀表达式转换为后缀表达式,顺利转换返回true,若转换过程中发现中缀表达式非法则返回false*/
int state_int = FALSE;
/*state_int记录状态,等于true表示刚读入的是数字字符,等于false表示刚读入的不是数字字符,*/
/*设置这个变量是为了在每输出一个整数后输出一个空格,以免连续输出的两个整数混在一起。*/
char c, c2;
int i,j = 0;
SeqStack ps ;
SStackSetNull(&ps); /*运算符栈*/
if (infix[0] == '\0')
return FALSE; /*不允许出现空表达式*/
for (i = 0; infix[i] != '\0'; i++)/*逐个读入表达式*/
{
c = infix[i];
switch (c)
{
case ' ':
case '\t':
case '\n':
if (state_int == TRUE)
suffix[j++] = ' ';/*状态从true转换为false时输出一个空格*/
state_int = FALSE;
break; /*遇到空格或制表符忽略*/
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
state_int = TRUE;
suffix[j++] = c; /*遇到数字输出*/
break;
case '(':
if (state_int == TRUE)
suffix[j++] = ' ';/*状态从true转换为false时输出一个空格*/
state_int = FALSE;
SStackPush(&ps, c); /*遇到左括号,入栈*/
break;
case ')':
if (state_int == TRUE)
suffix[j++] = ' ';/*状态从true转换为false时输出一个空格*/
state_int = FALSE; c2 = ')';
while (!SStackIsEmpty(&ps)) /*判断界限符号是否匹配*/
{
c2 = SStackGetTop(&ps);/*取栈顶*/
SStackPop(&ps,&c2); /*出栈*/
if (c2 == '(')
break;
suffix[j++] = c2;
}
if (c2 != '(')
{
free(&ps);
suffix[j++] = '\0';
return FALSE;
}
break;
case '+':
case '-':
if (state_int == TRUE)
suffix[j++] = ' ';
state_int = FALSE;
while(!SStackIsEmpty(&ps))
{
c2 = SStackGetTop(&ps);
if (c2 == '+' || c2 == '-' || c2 == '*' || c2 == '/')
{
SStackPop(&ps,&c2);
suffix[j++] = c2;
}
else
if(c2=='(')
break;
}
SStackPush(&ps, c);
break;
case '*':
case '/':
if (state_int == TRUE)
suffix[j++] = ' ';
state_int = FALSE;
while (!SStackIsEmpty(&ps))
{
c2 = SStackGetTop(&ps);
if (c2 == '*' || c2 == '/')
{
SStackPop(&ps,&c2);
suffix[j++] = c2;
}
else
if(c2=='+'||c2=='-'||c2=='(')
break;
}
SStackPush(&ps, c);
break;
default:
free(&ps);
suffix[j++] = '\0';
return FALSE;
}
}
if (state_int == TRUE)
suffix[j++] = ' ';
while (!SStackIsEmpty(&ps))
{
c2 = SStackGetTop(&ps);
SStackPop(&ps,&c2);
if (c2 == '(')
{
free(&ps);
suffix[j++] = '\0';
return FALSE;
}
suffix[j++] = c2;
}
free(&ps);
suffix[j++] = '\0';
return TRUE;
}
int CalculateSuffix( char * suffix, char * presult) /*计算表达式的值*/
{
int state_int = FALSE;
char num = '0', num1, num2;
int i;
char c;
SeqStack ps ;
SStackSetNull(&ps);
for (i = 0; suffix[i] != '\0'; i++)
{
c = suffix[i];
switch (c)
{
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
if (state_int == TRUE)
num = num * 10 + c - '0';
else
num = c - '0';
state_int = TRUE;
break;
case ' ':
case'\t':
case '\n':
if (state_int == TRUE)
{
SStackPush(&ps, num);
state_int = FALSE;
}
break;
case '+':
case '-':
case '*':
case '/':
if (state_int == TRUE)
{
SStackPush(&ps, num);
state_int = FALSE;
}
if (SStackIsEmpty(&ps)) /*如果栈为空,返回错误*/
{
free(&ps);
return FALSE;
}
num2 = SStackGetTop(&ps); SStackPop(&ps,&num2);
if (SStackIsEmpty(&ps)) /*如果为栈为空,返回错误*/
{
free(&ps);
return FALSE;
}
num1 =SStackGetTop(&ps);
SStackPop(&ps,&num1);
if (c == '+') /*两个操作数,进行运算*/
SStackPush(&ps, num1 + num2);
if (c == '-')
SStackPush(&ps, num1 - num2);
if (c == '*')
SStackPush(&ps, num1 * num2);
if (c == '/')
SStackPush(&ps, num1 / num2);
break;
default:
free(&ps);
return FALSE;
}
}
*presult = SStackGetTop(&ps) ; /*得到计算结果*/
SStackPop(&ps,presult);
if (!SStackIsEmpty(&ps)) /*判断不为空,返回错误*/
{
free(&ps);
return FALSE;
}
free(&ps);
return TRUE;
}
void getline(char * line, int limit) /*把表达式读入*/
{
char c;
int i = 0;
while (i < limit - 1 && (c = getchar()) != EOF && c != '\n') /*EOF为文件结束标志 -1*/
line[i++] = c;
line[i] = '\0';
}
int main()
{
char c, infix[MAXNUM], suffix[MAXNUM];
char result[40];
int flag = TRUE;
while (flag == TRUE) /*设置是否循环*/
{
printf("请输入一个表达式!\n");
gets(infix);
if(InfixtoSuffix(infix, suffix) == TRUE)
printf("该中缀表达式转换成的后缀表达式为:%s\n", suffix);
else
{
printf("无效的中缀表达式!\n");
printf("\n是否继续? (y/n)");
scanf("%c", &c);
if (c == 'n' || c == 'N')
flag = FALSE;
while (getchar() != '\n');
printf("\n");
continue;
}
if(CalculateSuffix(suffix, result) == TRUE)
printf("该表达式的结果为:%d\n", result[0]);
else
printf("无效的后缀表达式!\n");
printf("\n是否继续? (y/n)");
scanf("%c", &c);
if (c == 'n' || c == 'N')
flag = FALSE;
while (getchar() != '\n')
;
printf("\n");
}
return 0;
}
以上是 windows在**.exe中触发了一个断点,其原因可能是堆被损坏,这说明dll中有bug 的全部内容, 来源链接: utcz.com/p/194851.html