fork(2) download
  1. #include <iostream>
  2.  
  3. bool is_number(char const * s) {
  4. if (!s || !*s)
  5. return false; // нуллптр и пустая строка не число нихуя!
  6.  
  7. while (*s >= '0' && *s <= '9')
  8. ++s;
  9.  
  10. return !*s;
  11. }
  12.  
  13. int main() {
  14. std::cout << std::boolalpha
  15. << is_number("625462345") << std::endl
  16. << is_number("625f62345") << std::endl
  17. << is_number("") << std::endl
  18. << is_number("000000000000000") << std::endl
  19. << is_number(NULL) << std::endl;
  20. return 0;
  21. }
Success #stdin #stdout 0s 4280KB
stdin
Standard input is empty
stdout
true
false
false
true
false