엄청난 양의 오류가 있습니다. 무엇이 잘못 되었습니까? typedef를 사용하지 않으려 고 시도했지만 그게 무슨 문제입니까? 아무도 나를 디버깅 도와 드릴까요?C 스택 오류가 발생했습니다.
struct node {
int info;
struct node *link;
};
int main (void)
{
int choice;
struct node *top;
top = NULL;
while (1) {
printf("1.Push\n");
printf("2.Pop\n");
printf("3.Display\n");
printf("4.Quit\n");
printf("Enter your choice : ");
scanf("%d", &choice);
switch(choice) {
case 1:
push();
break;
case 2:
pop();
break;
case 3:
display();
break;
case 4:
exit(1);
default:
printf("Wrong choice\n");
}
}
return 0;
}
void push (void)
{
struct node *tmp;
int pushed_item;
tmp = malloc(sizeof(struct node));
printf("Input the new value to be pushed on the stack : ");
scanf("%d", &pushed_item);
tmp->info = pushed_item;
tmp->link = top;
top = tmp;
}
void pop (void)
{
struct node *tmp;
if (top == NULL)
printf("Stack is empty\n");
else {
tmp = top;
printf("Popped item is %d\n", tmp->info);
top = top->link;
free(tmp);
}
}
void display (void)
{
struct node *ptr;
ptr = top;
if (top == NULL)
printf("Stack is empty\n");
else {
printf("Stack elements :\n");
while (ptr != NULL) {
printf("%d\n", ptr->info);
ptr = ptr->link;
}
}
}
당신은, 제대로 코드를하시기 바랍니다 포맷 할 수 있습니까? –
그리고 오류가 무엇입니까? 정확한 오류 메시지를 게시하십시오. –
사용중인 컴파일러, 사용중인 컴파일러 옵션 및보고있는 특정 오류 출력을 게시하십시오. – bta