Stack in array

i want to create s.top public variable ..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
  #include<iostream.h>
//#define maxSize 5;

struct stack 
{
	int stk[5];
	int top;
};


stack s; 
s.top=1;


int push()
{
	int num;
	if(s.top==(5-1))
	{
		cout<<"Stack is full"<<endl;
		return 0;
	}
	else
	{
		cout<<"Enter Number";
		cin>>num;
		s.top=s.top+1;
		s.stk[s.top]=num;
		return 0;
	}
}

void main ()
{

	push();
}



--------------------Configuration: Stack - Win32 Debug--------------------
Build : warning : failed to (or don't know how to) build 'E:\VC6\Data Structre\Stack.cpp'
Compiling...
Stack.cpp
E:\VC6\Data Structre\Stack.cpp(12) : error C2143: syntax error : missing ';' before '.'
E:\VC6\Data Structre\Stack.cpp(12) : error C2501: 's' : missing storage-class or type specifiers
E:\VC6\Data Structre\Stack.cpp(12) : error C2371: 's' : redefinition; different basic types
E:\VC6\Data Structre\Stack.cpp(11) : see declaration of 's'
E:\VC6\Data Structre\Stack.cpp(12) : error C2143: syntax error : missing ';' before '.'
Error executing cl.exe.

Stack.obj - 4 error(s), 1 warning(s)
s.top=1; is a statement, it has to go in a function.

or the constructor... which is a function ;)

1
2
3
4
5
6
7
8
9
10
struct stack 
{
        stack()
        {
             top = 1;
        }

	int stk[5];
	int top;
};
Last edited on
sorry I'm not creating function for top...
I m creating global variable
Topic archived. No new replies allowed.