num.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. // NUM CODE
  11. //===============================================================================================================================================================================================================200
  12. //======================================================================================================================================================150
  13. // ISINTEGER FUNCTION
  14. //======================================================================================================================================================150
  15. int isInteger(char *str){
  16. //====================================================================================================100
  17. // make sure it's not empty
  18. //====================================================================================================100
  19. if (*str == '\0'){
  20. return 0;
  21. }
  22. //====================================================================================================100
  23. // if any digit is not a number, return false
  24. //====================================================================================================100
  25. for(; *str != '\0'; str++){
  26. if (*str < 48 || *str > 57){ // digit characters (need to include . if checking for float)
  27. return 0;
  28. }
  29. }
  30. //====================================================================================================100
  31. // it got past all my checks so I think it's a number
  32. //====================================================================================================100
  33. return 1;
  34. }
  35. //===============================================================================================================================================================================================================200
  36. // END NUM CODE
  37. //===============================================================================================================================================================================================================200
  38. #ifdef __cplusplus
  39. }
  40. #endif