You can write your own function. Check each character with isdigit() - if a test ever fails, then you can return false - it is not a number. If you have finished checking the string and have not returned false, then there was no non-numeric character, and the string is a number - you can return true.
You can write your own function. Check each character with isdigit() - if a test ever fails, then you can return false - it is not a number. If you have finished checking the string and have not returned false, then there was no non-numeric character, and the string is a number - you can return true.
That scenario sort of works but what about strings such as:
"12345678901234 567890123456789 012345678901234 567890123456789 0"?
It definitely is an integer in the theoretical sense of the meaning but in practice
it doesn't fit in a normal int nor long.
That scenario sort of works but what about strings such as:
"12345678901234 567890123456789 012345678901234 567890123456789 0"?
It definitely is an integer in the theoretical sense of the meaning but in practice
it doesn't fit in a normal int nor long.
kind regards,
Jos (<-- nitpicker ;-)
True...then again, in this case, would any solution work? No matter what method is used to determine that the string is, in fact, a number, the number remains too large to be represented.
Don't worry about being a nitpicker - picking at nits is how a coder gets better.
That scenario sort of works but what about strings such as:
"12345678901234 567890123456789 012345678901234 567890123456789 0"?
It definitely is an integer in the theoretical sense of the meaning but in practice
it doesn't fit in a normal int nor long.
kind regards,
Jos (<-- nitpicker ;-)
He can create, in his function, that longest number can have up to 6 chars(-32768 for int) and after entering 5th(or 6th if there is minus) that it automaticly break from input.Also he will need to include '-' sign as a option when inputing.
He can create, in his function, that longest number can have up to 6 chars(-32768 for int) and after entering 5th(or 6th if there is minus) that it automaticly break from input.Also he will need to include '-' sign as a option when inputing.
Comment