How to know if it is all numbers or not all numbers in 5 characters(length)? | Sololearn: Learn to code for FREE!
0

How to know if it is all numbers or not all numbers in 5 characters(length)?

Sample output: Enter character:12345 Valid length All numbers Enter character:123 Invalid length Enter character:123x5 Valid length Not all numbers

5th Jan 2019, 1:13 AM
Ejan Jearhson Navarrete
Ejan Jearhson Navarrete - avatar
4 Answers
+ 5
Test the length with strlen. Loop through the characters and test each for >= '0' and <= '9'.
5th Jan 2019, 1:47 AM
John Wells
John Wells - avatar
+ 4
I would agree with John Wells . I think that's the simplest way to do it. You can also use the character functions like 'isdigit()'
5th Jan 2019, 3:57 AM
Zeke Williams
Zeke Williams - avatar
0
Take a look at the source code..
5th Jan 2019, 1:20 AM
Da2
Da2 - avatar
0
Okay, thank you I will try.
5th Jan 2019, 5:39 AM
Ejan Jearhson Navarrete
Ejan Jearhson Navarrete - avatar