Question:

Correct my c-prog ....stack using array?

by  |  earlier

0 LIKES UnLike

include<stdio.h>

#include<conio.h>

void push();

void pop();

void disp();

int stack[10],top=-1;

void main()

int ch;

{

while(1)

{

clrscr();

printf("\n1.push \n2.pop \n3.dispaly \n4.exit");

printf("enter your choice");

scanf("%d"&ch);

switch(ch)

{

case 1: push();

break;

case 2: pop();

break;

case 3: disp();

brak;

case 4:

exit(0)

}

getch()

}

}

void push()

{

if(top==9)

printf("\n stack is full");

else

{

printf("enter the data");

scanf("%d",&d);

top=top+1;

stack[top]=d;

}

}

void pop()

{

if(top==-1)

printf("\n stack is empty");

else

printf("\n poped item is %d ", stack[top]);

top=top-1;

}

void disp()

{

if(top==-1)

printf("\n stack is empty");

else

for(i=top;i>0;i--)

printf("%d",stack[i]);

}

ERROR: line 8 : declaration syntax error

line 9: declaration terminated incorrectly

 Tags:

   Report

2 ANSWERS


  1. put the int ch; after void main under the curly braces as

    void main()

    {

    int ch;

    that would suffice...!


  2. 1:write int ch; in void main()   ...........

    2:put Comma in first scanf as scanf(&quot;%d&quot;,&amp;ch);  ............

    3:In case 3 write correctly break;   ...............

    4:In case 4 put Semi colon as exit(0);   .............

    5:Put  Semi colon afer getch as getch();    ..........

    6:write # in frony of include&lt;stdio.h&gt;      .........

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.