+ 1
how does strcmp() function work??
in what manner does it compare "abc" and "abd" or "abc" and "ABC" ???
6 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.
+ 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.
+ 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. 🤣
+ 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.
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.
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.