wizard of oz wizard of oz - 2 months ago 14x
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;
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");
printf("stack is not empty");

return 0;
int empty(int *s) {
if ( s -> myTop == -1)
return 1;
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 :)


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.