Last active
November 3, 2022 13:35
-
-
Save Silva97/9a50fecb43815eba5bf67a32e0e2f46d to your computer and use it in GitHub Desktop.
This file contains 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
#include <stdio.h> | |
#include <stdlib.h> | |
int getint(int *number); | |
int main() | |
{ | |
int n; | |
fputs("Digite um inteiro cara: ", stdout); | |
if ( getint(&n) ) | |
{ | |
printf("Para béns: %d\n", n); | |
} | |
else | |
{ | |
puts("Isso é um float, colega! Um float!"); | |
} | |
return 0; | |
} | |
int getint(int *number) | |
{ | |
char input[65]; | |
char *check; | |
fgets(input, sizeof input - 1, stdin); | |
*number = strtol(input, &check, 10); /* http://man7.org/linux/man-pages/man3/strtol.3.html */ | |
return (*check != '.' && *check != ','); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment