組むには組んだのですが、実行結果が思ったものになりません。
アドバイスをお願いします。
Cの知識は入門書レベル、環境はVine Linuxでgccでコンパイルしています。
欲しい実行結果:
入力
a
b
c
EOF
c
b
a
#include <stdio.h> typedef struct { char box[100]; int top; } st; void create(st *s); char top(st *s); void pop(st *s); void push(char x, st *s); int main(void) { st *s; int x; create(s); while ((x = getchar()) != EOF){ push(x, s); } printf("%c\n", top(s)); pop(s); printf("%c\n", top(s)); pop(s); printf("%c\n", top(s)); return 0; } void create(st *s) { s->top = 0; } char top(st *s) { return (s->box[s->top]); } void pop(st *s) { (s->top)--; } void push(char x, st *s) { (s->top)++; s->box[(s->top)] = x; }