Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdbool.h> // Include necessária
- // Abaixo das Includes
- bool isNumeric(const char string[]);
- // No fim do código, depois da "int main"
- bool isNumeric(const char string[]) // Aceita números inteiros de até 10 algarismos
- {
- int c = 0;
- bool foisinal;
- for(c; c < 10; c++)
- {
- if(string[c] == '\0') break;
- foisinal = false;
- if(string[c] < '0' || string[c] > '9')
- {
- if(c != 0) return 0;
- else if(string[c] != '+' && string[c] != '-') return 0;
- else foisinal = true;
- }
- }
- if(foisinal == false) return true;
- else return false;
- }
- // NÃO INCLUA O CÓDIGO ABAIXO NO SEU CÓDIGO !
- // Forma de uso:
- if(isNumeric("abc")) // retorna falso, ou seja, não entra no if
- if(isNumeric("123")) // retorna verdadeiro, ou seja, entra no if
- // Façam bom uso xD
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement