2014-11-06 26 views
10

Pop ve Push işlevlerini uygulayan bir program yazmaya çalışıyorum.C programlama, hata: çağrılan nesne bir işlev veya işlev işaretçisi değil

**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); 

} 
+5

Egzotik _missed semicolon_ durum için +1, stackoverflow'a hoşgeldiniz :) – Rerito

+0

Bu yorum beni çok fazla gülümsedi ... – Frederick

cevap

17

You: Sorun bu tamsayı sürekli değişiyor, böylece işlevine En tamsayı gösteren işaretçi geçmek çalışıyorum ama derlemeye çalıştığımda hep bu hat almak olduğunu sadece hata ile bu hat önce bir noktalı virgül cevapsız:

poped = stac[*t] <----- here 
(*t)--; 

bu tuhaf hatanın nedeni derleyici testere sth böyledir:

poped = stac[*t](*t)--; 

Bir tablodan gelen bir işlev göstericisine çağrı olarak yorumlanabilir, ancak bu açıkça bir anlam ifade etmemektedir; çünkü stac, bir dizi işlev işaretçisi değil, bir dizi ints'tır.

+0

Teşekkür ederim, hatayı arıyordum ve yapmadım. Cevapsız noktalı virgülü görüyorum. –

+1

@AbylIkhsanov - işte bu derleyicilerle hayat budur (; Bu iyi bir derstir - sık sık mesajda belirtilen satırdan önce hatayı aramanız gerekir. –