我在为数组提供新的 char 值时遇到问题。我不知道为什么即使 n 是 12 也会得到符号“<”?在这种情况下,我的程序应该将表达式更改int char* tab = "93+"
为一个值12
。
char* tab = "93+";
int b = sizeof (tab);
char* tmp = new char[b] ;
tmp [b-1] = '\0';
if(isdigit(tab[i]) && isdigit(tab[i+1]) ){
int n;
if(tab[i+2]=='+' || tab[i+2]=='-' || tab[i+2]=='*'){
switch(tab[i+2]){
case '+':
n = (tab[i]-'0') + (tab[i+1]-'0');
break;
case '-':
n = (tab[i]-'0') - (tab[i+1]-'0');
break;
case '*':
n = (tab[i]-'0') * (tab[i+1]-'0');
break;
}
tmp[i] = n+'0'; // I should have 12 but I get <
}
else if (tab[i+2]!='+' || tab[i+2]!='-' || tab[i+2]!='*'){
goto LAB;
}
}