C programming, error: called object is not a function or function pointer [closed]
Matthew Harrington
I am trying to write a program which implements the Pop and Push functions. The problem is, I am trying to pass the pointer that points to integer Top to the function, so that this integer keeps changing, but when I try to compile I always get this line:
**error: called object is not a function or function pointer (*t)--
#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);
} 0 1 Answer
You missed one semicolon just before that line with error:
poped = stac[*t] <----- here (*t)--;The reason for this strange error is that compiler saw sth like that:
poped = stac[*t](*t)--;Which it could interpret as a call to a function pointer coming from a table, but this obviously makes no sense, because stac is an array of ints, not an array of function pointers.
2