+ 1

how does strcmp() function work??

in what manner does it compare "abc" and "abd" or "abc" and "ABC" ???

24th Dec 2019, 7:25 PM
Sena Tunca
Sena Tunca - avatar
10 odpowiedzi
+ 10
Letters are compared by their ascii value. https://ascii.cl/index.htm?content=mobile strcmp compares both strings letter by letter, until a difference is found. That letter determines which string is 'lower'. If the first string is lower, you'll get -1 as return value, if it's larger, you get 1. Return value is 0 if equal to the end.
24th Dec 2019, 7:43 PM
HonFu
HonFu - avatar
+ 4
~ swim ~, but the length only matters when all the letters are equal, right? bb is still larger than abb, although abb is longer. So the length seems to function more as a tie breaker.
24th Dec 2019, 8:16 PM
HonFu
HonFu - avatar
+ 3
~ swim ~, lol, you've got some wild pro reputation: If in a hundred answers you make just one liiittle slip, people are so shocked that they have to downvote. 🤣
24th Dec 2019, 8:42 PM
HonFu
HonFu - avatar
+ 2
we have to downvote a wrong answer to not spread misinformation. I withdrew my vote after I saw the correction and I deleted my answer since it was superfluous now.
24th Dec 2019, 9:01 PM
Selin Genkur
0
Actually strcmp() works by using ascii value. i.e: a-a, b-b, c-c if all case 0 then this will same.. But in the case of A-a, the result will not be 0 becase ascii value is different. I think you have understand.
25th Dec 2019, 8:16 PM
Abdullah Al Noman Sakib
Abdullah Al Noman Sakib - avatar
0
It's compare two string If they both are same then Variable become 0 If they are not same then variable become greater than 0 Ex:c=strcmp (str1,str2); Here if they are same then c become 0 Or it becomes greater than 0.
26th Dec 2019, 2:08 AM
Bhushan Shinde
Bhushan Shinde - avatar