Re: whats wrong with this simple C stack program?
Quote:
|
Originally Posted by nix
Code:
for (;;)
{
printf("1....push\n");
printf("2....pop\n");
printf("3....display\n");
printf("4....exit\n");
printf("enter the choice\n");
scanf("%d",&choice);
switch(choice)
{
case 1:push();
break;
case 2:pop();
break;
case 3:display();
break;
default:exit(0);
}
/*Move the getch(); here*/
}
getch(); /*remove getch from here and move it to green line*/
}
|
Both the problems are due to a single misplaced statement
1. You get a "code unreachable" message because you've placed the getch() outside an infinite loop
2. You're able to enter only one value because your getch is not inside the loop.
Just move the getch() to the line in green in the above segment
__________________
Desktop: P4 2.8E, Intel 865GBF, 512MB Hynix PC3200, Samsung SV1204H 120GB, Samsung SW-248F, Creative Inspire 4400, Samsung 793MB, Compro PVR/FM, WinLIRC
Laptop: HP Pavilion dv8210us
Last edited by mod-the-pc; 10-11-2006 at 12:43 AM.
|