Like iMalc said, you should look at the FAQ, there's useful stuff in there.
no matter what i input, the exe. window close itself
It does so because your program is structured that way. If you want it to ask for user input until the user gives a certain input, then you need to use a loop.
however if i type 7 (which is out of 1-6), it shows please enter again
Ok. Let's say you want the user to enter a number between 1 and 6 inclusively. Well it's quite simple:
Code:
int i;
int option;
// ...
do
{
printf("Options: ");
i = scanf("%d", &option);
while (getchar() != '\n'); // Empty the input buffer
} while (i != 1 || option < 1 || option > 6);
That said, here is how i write a typical menu function:
Code:
int continu = 1;
// ...
do
{
// Print menu option here
puts("1. Do something");
puts("2. Exit");
do
{
// Read user input here (as previously shown)
} while (i != 1 || choix < 1 || choix > 2);
switch(choix)
{
case 1:
// Do something here
break;
default:
continu = 0;
break;
}
} while (continu);
Also, note that you can output the "spade character" this way: printf("\6");.
iMalc: You changed your avatar, right ? I think the last one was showing heapsort; is this one something like shaker sort ?