user3215228
user3215228

Reputation: 313

Compare digits in character string

Please I am trying to find built in function that compares not the alphabet but the digits in two character array. for example

if in char array1[50] there is a number 500 and in char array2[50] there is a number 100 so I should be able to compare which one is bigger, in this case 500 is bigger which is array1 so what is the built in function for this. Please help me.

Upvotes: 0

Views: 797

Answers (2)

wacky6
wacky6

Reputation: 145

prepend(add '0' at the beginning) '0' so both strings become same in length, then you can use strcmp(), or std::string::compare() depending on your data type.

Upvotes: 1

Paul Evans
Paul Evans

Reputation: 27567

Use boost::lexical_cast:

if (boost::lexical_cast<int>(array1[50]) > boost::lexical_cast<int>(array2[50]))
{
    // array1[50] bigger than array2[50]
}

Upvotes: 0

Related Questions