编辑代码

#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 100

typedef struct {
    int data[MAXSIZE];
    int top;
} SEQSTACK;

SEQSTACK *s;

void Init_Stack(SEQSTACK *s){
    s->top = -1;
}

int Stack_Empty(SEQSTACK *s){
    if (s->top == -1)
        return 1;
    else
        return 0;
}

void Push_Stack(SEQSTACK *s, int x){
    if (s->top == MAXSIZE - 1)
        printf("Stack full\n");
    else {
        s->top++;
        s->data[s->top] = x;
    }
}

int Pop_stack(SEQSTACK *s){
    int x;
    if (Stack_Empty(s)) {
        printf("Stack empty\n");
        x = -1;
    } else {
        x = s->data[s->top];
        s->top--;
    }
    return x;
}

int main(){
    int num, remainder;
    s = (SEQSTACK *)malloc(sizeof(SEQSTACK));
    Init_Stack(s);
    printf("输入十进制数字: ");
    scanf("%d", &num);
    while (num != 0) {
        remainder = num % 8;
        Push_Stack(s, remainder);
        num = num / 8;
    }
    printf("它的八进制为: ");
    while (!Stack_Empty(s)) {
        printf("%d", Pop_stack(s));
    }
    printf("\n");
    return 0;
}