我想寫一個實現Pop和Push函數的程序。問題是,我試圖傳遞的指向整數頂部的功能,使這個整數不斷變化的指針,但是當我嘗試編譯我總是得到這一行:C編程,錯誤:被調用的對象不是函數或函數指針
#include<stdio.h>
#include<stdlib.h>
#define MAX 10
int push(int stac[], int *v, int *t)
{
if((*t) == MAX-1)
{
return(0);
}
else
{
(*t)++;
stac[*t] = *v;
return *v;
}
}
int pop(int stac[], int *t)
{
int popped;
if((*t) == -1)
{
return(0);
}
else
{
popped = stac[*t]
(*t)--;
return popped;
}
}
int main()
{
int stack[MAX];
int value;
int choice;
int decision;
int top;
top = -1;
do{
printf("Enter 1 to push the value\n");
printf("Enter 2 to pop the value\n");
printf("Enter 3 to exit\n");
scanf("%d", &choice);
if(choice == 1)
{
printf("Enter the value to be pushed\n");
scanf("%d", &value);
decision = push(stack, &value, &top);
if(decision == 0)
{
printf("Sorry, but the stack is full\n");
}
else
{
printf("The value which is pushed is: %d\n", decision);
}
}
else if(choice == 2)
{
decision = pop(stack, &top);
if(decision == 0)
{
printf("The stack is empty\n");
}
else
{
printf("The value which is popped is: %d\n", decision);
}
}
}while(choice != 3);
printf("Top is %d\n", top);
}
+1爲異國情調的_missed分號_情況下,歡迎來到stackoverflow :) – Rerito 2014-11-06 13:09:58
這個評論讓我微笑很多次... – Frederick 2015-04-09 21:26:36