C编程,错误:被调用的对象不是函数或函数指针[已关闭]
发布时间:2020-12-16 05:38:23 所属栏目:百科 来源:网络整理
导读:我正在尝试编写一个实现Pop和Push功能的程序.问题是,我试图将指向整数Top的指针传递给函数,这样整数不断变化,但是当我尝试编译时,我总是得到这个行: **error: called object is not a function or function pointer (*t)– #includestdio.h#includestdlib.h
我正在尝试编写一个实现Pop和Push功能的程序.问题是,我试图将指向整数Top的指针传递给函数,这样整数不断变化,但是当我尝试编译时,我总是得到这个行:
#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 poped; if((*t) == -1) { return(0); } else { poped = stac[*t] (*t)--; return poped; } } int main() { int stack[MAX]; int value; int choice; int decision; int top; top = -1; do{ printf("Enter 1 to push the valuen"); printf("Enter 2 to pop the valuen"); printf("Enter 3 to exitn"); scanf("%d",&choice); if(choice == 1) { printf("Enter the value to be pushedn"); scanf("%d",&value); decision = push(stack,&value,&top); if(decision == 0) { printf("Sorry,but the stack is fulln"); } else { printf("The value which is pushed is: %dn",decision); } } else if(choice == 2) { decision = pop(stack,&top); if(decision == 0) { printf("The stack is emptyn"); } else { printf("The value which is poped is: %dn",decision); } } }while(choice != 3); printf("Top is %dn",top); } 解决方法
你错过了一行之前错过了一个分号:
poped = stac[*t] <----- here (*t)--; 这个奇怪的错误的原因是编译器看到这样的: poped = stac[*t](*t)--; 它可以解释为来自表的函数指针的调用,但这显然没有任何意义,因为stac是一个int数组,而不是一个函数指针数组. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |