Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Search - "strcmp"
-
My code was doing the exact oposite of what I wanted it to do and it took me about 2 hours to find out that strcmp() returns 0 when the strings match, problem solved, fml.4
-
I was shocked when one of my university teachers said there was no difference between strcmp(input, exit); and strcmp(input, "exit");1
-
LOL that's why I love C!
The function pointer cast for strcmp because qsort expects a compare function with two const void * pointers instead of two const char * pointers, that's just beautiful.
Not to mention the hack to abuse strcmp on a struct - which just works because the first struct member is a string and the rest just gets swapped with memcpy as opaque data.
I guess that wouldn't pass a code review at work. :-)6 -
People here expect me to use strncmp(str,"ABC",strlen("ABC")) because they think strcmp(str,"ABC") is going to crash. Because they've had experiences of using strcmp and getting crashed.
All they did was, pass inside strcmp, strings that did not carry terminating null character but won't accept if i told so.2 -
The strcmp(3) manual page takes me closer to god: "strcmp() function compares the two strings s1 and s2. It returns an integer less than, equal to, or greater than zero if s1 is found, respectively, to be less than, to match, or be greater than s2."