num.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // #ifdef __cplusplus
  2. // extern "C" {
  3. // #endif
  4. //===============================================================================================================================================================================================================200
  5. // DESCRIPTION
  6. //===============================================================================================================================================================================================================200
  7. // Returns: 0 if string does not represent integer
  8. // 1 if string represents integer
  9. //===============================================================================================================================================================================================================200
  10. // FUNCTION
  11. //===============================================================================================================================================================================================================200
  12. int
  13. isInteger(char *str){
  14. //====================================================================================================100
  15. // make sure it's not empty
  16. //====================================================================================================100
  17. if (*str == '\0'){
  18. return 0;
  19. }
  20. //====================================================================================================100
  21. // if any digit is not a number, return false
  22. //====================================================================================================100
  23. for(; *str != '\0'; str++){
  24. if (*str < 48 || *str > 57){ // digit characters (need to include . if checking for float)
  25. return 0;
  26. }
  27. }
  28. //====================================================================================================100
  29. // it got past all my checks so I think it's a number
  30. //====================================================================================================100
  31. return 1;
  32. }
  33. //===============================================================================================================================================================================================================200
  34. // END
  35. //===============================================================================================================================================================================================================200
  36. // #ifdef __cplusplus
  37. // }
  38. // #endif