hello i got a problem with comparing two char* variables that contains numbers for example
char1 = "999999" and char2="11111111"
when i am using the strcmp function it will return that char1 variable is greater than char2
even tho its wrong.
(i know that i can compare with using the atoi function till 9 chars inside the string but i need to use 10 so it cuts this possibility).
hello i got a problem with comparing two char* variables that contains numbers for
Share
A slightly more cumbersome way, that avoids
atoiand friends, is to prefix the shorter of the two strings with zeroes. Or, assuming there are no prefixing zeroes, simply first comparing the length (since shorter strings must have a lower value), then running a lexiographic comparison:Oh, and this requires the strings to contain non-negative numbers.