Well this question is about C and C++ as strcmp
is present in both of them.
I came across this link: C library function - strcmp().
Over here it was explained the return values of strcmp
. I know that every function, how much ever safe it is, can fail. Thus, I knew that even strcmp
can fail at some time.
Also, I came across this question which also explained the return values of strcmp
. After searching a lot, I could not find a website which explained how to check if strcmp
could fail.
I first had a thought that it would return -1, but it turned out that it returns numbers < 0 if the first string is smaller. So can someone tell me how to check if strcmp
has failed.
EDIT: well, I do not understand the point of strcmp
not failing. There are many ways in which a function fails. For example, in one comment, it was written that if a stack doesn't extend, it might cause a stack overlow. No program in any language is absolutely safe!