[問題] 請問字串堆疊的問題???

看板C_and_CPP作者 (我的雞巴女友)時間7年前 (2018/06/07 15:51), 編輯推噓2(203)
留言5則, 4人參與, 7年前最新討論串1/1
請問各位強者 我想把字串寫入堆疊,然後再從堆疊中取出 請問我的程式該怎麼改!!因為一直出現錯誤 #include <stdio.h> #include <stdlib.h> #define MAXSTACK 100 /*定義最大堆疊容量*/ char stack[MAXSTACK]; //堆疊的陣列宣告 int top=-1; //堆疊的頂端 int isEmpty(); void push(char string); char pop(); int main(int argc, char *argv[]) { char string[3]; int i; printf("請依序輸資料:\n"); fgets(string[0], 100, stdin); push(string) fgets(string[0], 100, stdin); push(string); fgets(string[0], 100, stdin); push(string); printf("====================\n"); while(!isEmpty()){ printf("堆疊彈出的順序為:%d\n",pop()); } pop(); return 0; } /*判斷是否為空堆疊*/ int isEmpty() { if(top==-1) { return 1; } else { return 0; } } /*將指定的資料存入堆疊*/ void push(string) { if(top>=MAXSTACK){ printf("堆疊已滿,無法再加入\n"); } else { top++; stack[top]=string; } } /*從堆疊取出資料*/ char pop(){ char data; if(isEmpty()) { printf("堆疊已空\n"); }else { data=stack[top]; top--; return data; } } -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 61.228.242.36 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1528357909.A.6AF.html

06/07 15:54, 7年前 , 1F
字串處理的部分整個錯了
06/07 15:54, 1F

06/07 15:54, 7年前 , 2F
fgets用法完全錯誤
06/07 15:54, 2F

06/07 15:56, 7年前 , 3F
而且這種語法錯誤應該會有錯誤訊息 下次請先google
06/07 15:56, 3F

06/07 20:08, 7年前 , 4F
你如果想印字元迴圈內那個printf要用%c才對
06/07 20:08, 4F

06/16 12:06, 7年前 , 5F
應該不只上面提到的問題.......
06/16 12:06, 5F
文章代碼(AID): #1R6EGLQl (C_and_CPP)