Я использовал стек, чтобы сделать что-то с таким символом, как код ниже. Когда я запускаю эту программу, она ничего не печатает. Я попытался отладить, но он имеет ошибку "программа получила сигнал SIGTRAP, trap / breakpoint trap". Пожалуйста, помогите. Tks за вашу помощь.
#include <stdio.h>
#include <stdlib.h>
short IsEmpty(int *top){
if (*top==-1) return 1;
return 0;
}
short IsFull(int *top, int capacity){
if (*top == capacity) return 1;
return 0;
}
void Push(int *top, int capacity, char *stack, char value){
if (IsFull(top, capacity)==1) printf("stack overflow");
else{
++*top;
stack[*top]=value;
}
}
void Pop(int *top, int capacity, char *stack){
if (IsEmpty(top)==1) printf("stack underflow");
else{
free(stack[*top]);
--*top;
}
}
int main(){
int top=-1;
int capacity;
printf("import capacity of stack: "); scanf("%d",&capacity);
char *stack=(char *)malloc(capacity*sizeof(char));
Push(&top, capacity, stack, 'A');
Push(&top, capacity, stack, 'B');
Push(&top, capacity, stack, 'C');
Pop(&top, capacity, stack);
Pop(&top, capacity, stack);
Push(&top, capacity, stack, 'D');
printf("%s",stack[1]);
free(stack);
return 0;
}