16

strcmp() is the most confusing function of all time. It returns zero when everything matches.

Comments
  • 1
    And returns the difference otherwise

    Also i hate c
  • 1
    So if you feed it the same strings, but with a 0 appended to one of them...
  • 3
    bool my_cmp(char *a, char *b) {
    return strcmp(a,b) == 0;
    }

    Problem solved.
  • 0
    @Kaji I thought you would get a positive if '0' is appended to the right param, since 0x60 > 0x0
  • 3
    I once helped guy with some easy program he tried to do, that had string input - space delimited commands and variables. I rather work with Python, but hey, basic logics apply to any language. After hour of "wtf it should work" we found out that every strcmp we used was expected to give positive value when command occured... of course it does not. Silly us.
  • 3
    I'm not sure why you would expect it to return something other than 0? It isn't named isStrEqual
  • 0
    @willol This does help clear the confusion. Thanks.
Add Comment