以下代碼片段是評估後綴表達式的程序的一部分。我對C編程沒有太多經驗,所以請原諒我的知識。我不明白代碼中突出顯示的部分在做什麼。以下是C語言代碼片斷在做什麼?
char str[100];
int i, data = -1, operand1, operand2, result;
/* Get the postfix expression from the user */
printf("Enter ur postfix expression:");
fgets(str, 100, stdin);
for (i = 0; i < strlen(str); i++)
{
if (isdigit(str[i]))
{
/*
* if the i/p char is digit, parse
* character by character to get
* complete operand
*/
data = (data == -1) ? 0 : data;
data = (data * 10) + (str[i] - 48); //What is happening here
continue;
}
調試你的代碼,你就知道了。 – Maroun
@MarounMaroun以下是完整的代碼供您參考http://see-programming.blogspot的鏈接。in/2013/02/evaluate-postfix-expression-using.html – pacman7845421
您確定代碼中沒有多餘的星號? – moeCake