[問題] struct與函數的使用問題
C語言
新手學不久請見諒@@
最近在學資料結構
用struct嘗試把堆疊應用卻出了問題
首先結構是這樣:
struct Stack{
int top;
int items[100];
} s;
然後是push的函數:
void push(struct Stack s,char a)
{
s.top++;
s.items[s.top]=a;
}
程式能過但output卻不符合
debug後發現結構裡的東西在跑函數時會變動
但函數跑完一出去就回復原狀了
試過把struct Stack s打在main裡面但沒用
之前有遇過類似問題好像是call by value/address的關係
沒辦法之下有試過無腦加'*'和'&'等但都過不了...
網路上也查不到相關問題
想請教是哪邊出了問題...
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.236.226.147
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1443724843.A.6F4.html
→
10/02 03:28, , 1F
10/02 03:28, 1F
→
10/02 03:30, , 2F
10/02 03:30, 2F
→
10/02 03:31, , 3F
10/02 03:31, 3F
→
10/02 03:33, , 4F
10/02 03:33, 4F
→
10/02 03:33, , 5F
10/02 03:33, 5F
→
10/02 03:34, , 6F
10/02 03:34, 6F
→
10/02 03:34, , 7F
10/02 03:34, 7F
→
10/02 03:35, , 8F
10/02 03:35, 8F
推
10/02 03:40, , 9F
10/02 03:40, 9F
→
10/02 08:32, , 10F
10/02 08:32, 10F
→
10/02 12:02, , 11F
10/02 12:02, 11F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章
-3
16