[問題] 問題出在哪??compile不過..

看板C_and_CPP (C/C++)作者 (清心寡愈)時間16年前 (2009/04/06 13:04), 編輯推噓2(206)
留言8則, 3人參與, 最新討論串1/2 (看更多)
#include <stdio.h> #include <stdlib.h> #define Stacksize 80 #define TRUE 1 #define FALSE 0 int input_infix(char); // 中序轉後序 char priority(int); // 決定運算子優先順序 void evalute_subvalue(int); //計算程式 void Push_operand(struct stack_operand int*, int);//放值進運算元堆疊 void Push_operator(struct stack_operator char*, char);//放值進運算子堆疊 int Pop_operand(struct stack_operand int*);//拿運算元出堆疊 char Pop_operator(struct stack_operator char*);//拿運算元出堆疊 //////////////////////////////////// /* 運算元堆疊宣告 */ //////////////////////////////////// struct stack_operand { int top; int stack[Stacksize]; }; //////////////////////////////////// /* 運算子堆疊宣告 */ //////////////////////////////////// struct stack_operator { char top; char stack[Stacksize]; }; //////////////////////////////////// /* 主程式 */ //////////////////////////////////// int main(void) { int input[Stacksize]; printf("輸入運算式:"); scanf("%s", input); input_fix(input); system("pause"); return 0; } //////////////////////////////////// /* 中序轉後序 */ //////////////////////////////////// int input_infix(char* infix) { int i=0; char symb; int op; struct stack_operand ope_rand; struct stack_operator oper_ator; ope_rand.top = -1 ; oper_ator.top = -1 ; while(!'\0') { symb = infix[i]; if (symb = '+'||'-'||'*'||'/'){ Push_operator(*oper_ator.top, symb); } else if (symb == ')') { while((op = Pop_operator(*oper_ator.top))!='(') { evalute_subvalue(op); continue; }} else while (priority(symb) <= priority(oper_ator.top)) { op = Pop_operand(*ope_rand.top); evalute_subvalur(op); } Push_operator(*oper_ator.top, symb); while() { op = Pop_operand(*ope_rand.top); evalute_subvalue(op); } printf("ans:%c",*ope_rand->stack[0]); } //////////////////////////////////// /* 判斷運算元優先順序 */ //////////////////////////////////// int priority(char symb) { int p; switch(op) { case '+': case '-': p = 1; break; case '*': case '/': p = 2; break; default: p = 0; break; } return p; } //////////////////////////////////// /* 計算函式 */ //////////////////////////////////// void evalute_subvalue(int op) { int a,b; int op, new_value; b = int Pop(*ope_rand.top); a = int Pop(*ope_rand.top); switch(op) { case '+': return (new_value = a + b); case '-': return (new_value = a - b); case '*': return (new_value = a * b); case '/': return (new_value = a / b); } Push(*ope_rand.top , new_value); } //////////////////////////////////// /* PUSH */ //////////////////////////////////// void Push_operand(struct stack_operand *ps , int symb) { if(ps.top >= Stacksize - 1) printf("The stack is full \n"); retun FALSE else ps->stack[++(ps->top)] = symb; return; } void Push_operator(struct stack_operator *ps , char symb) { if(ps.top >= Stacksize - 1) printf("The stack is full \n"); retun FALSE; else ps->stack[++(ps->top)] = symb; return; } //////////////////////////////////// /* POP */ //////////////////////////////////// int Pop_operand(struct stack_operand *ps) { if(ps.top < 0) printf("The stack is empty \n"); retun FALSE; else return(ps->stack[ps->top --]); } int Pop_operator(struct stack_operator *ps) { if(ps.top < 0) printf("The stack is empty \n"); retun FALSE; else return(ps->stack[ps->top --]); } 小弟這個程式一直沒辦法compile... 可是我找不到錯誤到底在哪... 是語法有錯嗎?? 還是其他的問題呢?? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.134.25.205

04/06 13:13, , 1F
試著學會看錯誤訊息吧, 每次都拿上來問不是辦法
04/06 13:13, 1F

04/06 13:14, , 2F
if 後面跟不只一個敘述時要用 { } 括起來
04/06 13:14, 2F

04/06 15:17, , 3F
宣告副程式有問題,宣告變數陣列也有=w=
04/06 15:17, 3F

04/06 15:18, , 4F
op是int 拿去check char'+-*/' 還滿恐怖的...
04/06 15:18, 4F

04/06 15:32, , 5F
還好還好 isdigit()函式本身也是int,memset第二個參數也是
04/06 15:32, 5F

04/06 15:33, , 6F
因為int可以裝char,所以不會有問題,反過來才有截斷問題
04/06 15:33, 6F

04/06 15:34, , 7F
struct stack_operand 'int','char'你用內建型別當變數名稱
04/06 15:34, 7F

04/06 15:35, , 8F
且在函式原型出現時 你還沒給他認識struct
04/06 15:35, 8F
文章代碼(AID): #19sOr8LL (C_and_CPP)
文章代碼(AID): #19sOr8LL (C_and_CPP)