vicenteninjat Posted June 26, 2012 at 02:58 PM Report Share #465662 Posted June 26, 2012 at 02:58 PM Boas Tenho um programa que recebe números e queria proteger a entrada de letras para não bloquear o programa. como posso fazer isto? obrigado com os melhores cumprimentos. Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted June 26, 2012 at 03:06 PM Report Share #465667 Posted June 26, 2012 at 03:06 PM podes usar a combinação fgets/sscanf: int input(FILE * stream, int * result) { int valid = 0; char buffer[256]; // falta a verificacao de argumentos while (!valid) // ciclo de leitura { if (fgets(buffer, 256, stream) != NULL) // ler uma linha do stream { if (sscanf(buffer, "%d", result) == 1) // interpretar a linha lida valid = 1; // leitura valida } } return 0; } nota : isto é uma opção de leitura bloqueante, mas podes tirar ideias 1 Report IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now