Jump to content

[Resolvido] Duvida sobre codigo


Carlos7

Recommended Posts

Boas, pessoal tenho um menu e tenho o codigo do menu desta forma:

do {
    printf("0 - Exit\n");
    printf("1 - Menu Student\n");
    printf("2 - Menu Instructor\n");
    printf("3 - Menu 3\n");
    printf("4 - Menu 4\nOption:\n");
    while (!scanf("%u", &option) || option < 0 || option > 4 || getchar() != '\n') {  //perceber
	    while (getchar() != '\n'); //perceber
	    printf("Invalid Option!\nOption:\n");
    }

//Switch case das opcoes
//......
}

Não consigo perceber a parte que coloquei no comentario...

Funciona correctamente mas nao estou a perceber o que fazem aquelas linhas, alguém pode ajudar?

Link to comment
Share on other sites


while (                      // enquando
   !scanf("%u", &option) || // não ter lido um valor numérico
   option < 0 ||            // o valor numérico lido for inferior a 0
   option > 4 ||            // o valor numérico for superior a 4
   getchar() != '\n')       // o caracter seguinte ao lido for diferente de fim de linha
{
 while (getchar() != '\n'); // limpar o buffer de leitura
 printf("Invalid Option!\nOption:\n");
}
IRC : sim, é algo que ainda existe >> #p@p
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.