Sto imparando C e sto usando "getchar()" per fermare il comando windows così posso vedere gli esercizi che sto facendo ma semplicemente non funziona. heres un campione:Perché non getchar() mi aspetta per premere invio dopo scanf()?
#include <stdio.h>
int main()
{
int value;
printf("1. option 1.\n2. option 2.\n3. option 3.\n4. Exit\n\nMake an option: ");
scanf("%d", &value);
switch (value)
{
case 1:
printf("you selected the option 1.");
break;
case 2:
printf("you selected the option 2.");
break;
case 3:
printf("you selected the option 3.");
break;
case 4:
printf("goodbye");
break;
default:
printf("thats not an option");
break;
}
getchar();
return 0;
}
questo è l'output:
- opzione 1.
- opzione 2.
- opzione 3.
- Uscita.
Fai un'opzione: 1
è stata selezionata l'opzione 1.
processo restituito 0 (0x0) Tempo di esecuzione: 3.453 s
Premere un tasto qualsiasi per continuare.
Perché non attende l'input di "getchar()"?
Vedi http://stackoverflow.com/questions/1384073/problem-with-flushing-input-stream-c/1384089. –