wizard of oz wizard of oz - 3 months ago 19
C Question

stack in C , expected expression before 'int'

im completely new in programming and i got a lot error :)

im trying to code my first stack like this and try to check empty :

#define SIZE 10
struct stack {
int myTop;
int items[SIZE];
};
int empty(int *s);
int main() {
struct stack s;
s.items;
s.myTop;
int i;
int x;
for ( i = 0 ; i < SIZE ; i ++ ) {
printf("enter you element");
scanf("%d", &s.items[i]);
}
if (empty(int *s))
printf("stack is empty");
else
printf("stack is not empty");


getchar();
return 0;
}
int empty(int *s) {
if ( s -> myTop == -1)
return 1;
else
return 0;
}
enter code here


and i got this errors :
in line 24 expected expression befor 'int' , what its mean for god sake ?
and others
plz help the new guy :)

Answer

This line is the problem:

if (empty(*s))

Change it to:

if (empty(&s))

Also your method prototype is wrong, it should be:

int empty(struct stack *s) 

You cannot pass a struct pointer to an int pointer.

Also you are not assigning anything here:

s.items; // = ?
s.myTop; // = ?

Not sure what you are trying but your fully compilable code (ignoring warnings) is here.

Comments