+ 4

What does it mean when a string is more or less than another string?

I was studying one of the challenge questions for C and couldn't understand what it meant by a string is less/more than the other string. https://code.sololearn.com/cJ9syaYHnzdy/?ref=app https://www.tutorialspoint.com/c_standard_library/c_function_strcmp.htm

4th May 2019, 6:27 PM
silentlearner
silentlearner - avatar
2 odpowiedzi
+ 5
Two strings get compared char by char. If equal - next letter. As soon as you find that one char is lower than the other, you have your result. Base of comparison is the ASCII table.
4th May 2019, 6:41 PM
HonFu
HonFu - avatar
+ 11
silentlearner String is compared by string handling function strcmp(str,str1); If str is alphabetically greater than str1 then it will return 1. If str is alphabetically less than str1 then it will return -1. If str and str1 are alphabetically equal it will return 0. In your code, str="Solo"; and str1="Learn"; When comparing this two strings, strcmp(str,str1); The 'S' of str is alphabetically greater than 'L' of str1 therefore it will return 1.
4th May 2019, 7:08 PM
Yamin Mansuri
Yamin Mansuri - avatar