DUDES, NEED CORRECTION HERE.. PLEASE

can u please correct this code i made?
its supposed to push,pop,makeempty,empty and print, depending on the choice of the user.. u'll get the idea.. here's the code..
can u please revise it and highlight what you've changed..
i would really appreciate this.. thanks in advance..

heres my code

#include <stdio.h>
#include <conio.h>
#include <ctype.h>

char stack[10];
char ch;
int top;

void Push(char c){
printf("Enter a character to push: ");
if(top==9){
printf("Stack is full!");
}
else{
top++;
stack[top] = c;
}
getche();
}

char Pop(){
if(top==-1){
printf("Stack is empty!");
}
else{
return stack[top--];
}
}

void Print(){
if(top==-1){
printf("Stack is empty!");
}
else{
while(top!=-1)
printf("%c", Pop());
}
}

void MakeEmpty(){
if(top==-1){
printf("Stack is already empty!");
}
else{
top=-1;
}
}

int Empty(){
if(top==-1){
return 1;
}
else{
return 0;
}
}

int main(){
char c;

printf("MAIN MENU: \nA.PUSH \nB.POP \nC.PRINT \nD.MAKE EMPTY \nE.EMPTY\n");
scanf("%c", &ch);

switch (ch){
case 'a':
Push(getche());
break;

case 'b':
c = Pop();
break;

case 'c':
Print();
break;

case 'd':
MakeEmpty();
break;

case 'e':
if(Empty()==1){
printf("Empty");
}
else{
printf("Not Empty");
}
break;


return 0;
getch();
}
}
Quite a few issues here:
1) Please enclose your code in block so that it's readable
2) you call getch() right after return 0. getch() will NEVER get called
3) When you start i assume your stack is empty, now when your stack is empty i believe you want top = -1, but this is not what will happen as top has not been explicitly defined to be -1 at the beginning. Technically speaking the value of top is undefined but typically it'll be 0 not -1.
4) Really minor but your code seem to be C-sytle not C++-style (Based on your function calls etc). I don't really care but if it's meant to be C++ code i've found that some ppl mind if you use alot of C functions
5) Even smaller and is just a manner of opinion, but should Print really pop from the stack?
Topic archived. No new replies allowed.