Created
May 24, 2014 14:31
-
-
Save pluralism/f1269c1e6f49dcf83bc1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int getMaxNumber(char *number) | |
| { | |
| long int tmp_number; | |
| char *lptr; | |
| tmp_number = strtol(number, &lptr, 10); | |
| //No valid conversion could be performed | |
| if(tmp_number == 0L) | |
| { | |
| fprintf(stderr, "[!] Erro na funcao getMaxNumber(...). Nao foi possivel converter o numero...\n"); | |
| exit(EXIT_FAILURE); | |
| } | |
| /** | |
| * If the value read is out of the range of representable values by a long int, the function returns LONG_MAX * or LONG_MIN (defined in <climits>), and errno is set to ERANGE. | |
| */ | |
| if((tmp_number == LONG_MAX || tmp_number == LONG_MIN) && errno == ERANGE) | |
| { | |
| fprintf(stderr, "[!] Erro na funcao getMaxNumber(...). Nao foi possivel converter o numero...\n"); | |
| exit(EXIT_FAILURE); | |
| } | |
| if(tmp_number <= 1) | |
| { | |
| fprintf(stderr, "[!] Erro! O numero nao pode ser menor ou igual a 1! A sair...\n"); | |
| exit(EXIT_FAILURE); | |
| } | |
| return tmp_number; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment