gpt4 book ai didi

c - 出现错误,提示未识别的函数 "push"、 "pop"和“display”,我应该添加什么来修复它?

转载 作者:行者123 更新时间:2023-11-30 14:30:50 24 4
gpt4 key购买 nike

#include<stdio.h>

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>(TOP)
#include<fstream.h>

#define MAX 5

int top = -1;
int stack_arr[MAX];

main()
{
int choice;
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");
}/*End of switch*/
}/*End of while*/
}/*End of main()*/

push()
{
int pushed_item;
if(top == (MAX-1))
printf("Stack Overflow\n");
else
{
printf("Enter the item to be pushed in stack : ");
scanf("%d",&pushed_item);
top=top+1;
stack_arr[top] = pushed_item;
}
}/*End of push()*/

pop()
{
if(top == -1)
printf("Stack Underflow\n");
else
{
printf("Popped element is : %d\n",stack_arr[top]);
top=top-1;
}
}/*End of pop()*/

display()
{
int i;
if(top == -1)
printf("Stack is empty\n");
else
{
printf("Stack elements :\n");
for(i = top; i >=0; i--)
printf("%d\n", stack_arr[i] );
}
}/*End of display()*/

最佳答案

您应该在 main 之前转发声明这些函数:

void push();
void pop();
void display();

或将实际声明移至 main 之上。

关于c - 出现错误,提示未识别的函数 "push"、 "pop"和“display”,我应该添加什么来修复它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2639169/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com