What does strcmp return if two similar strings are of different lengths?

后端 未结 5 1291
庸人自扰
庸人自扰 2021-02-19 15:09

I understand that if you have \'cat\' (string1) and \'dog\' (string2) in strcmp (this is a C question) then the return value of strcmp would be less than 0 (since \'cat\' is lex

5条回答
  •  死守一世寂寞
    2021-02-19 15:45

    From man strcmp:

    The strcmp() and strncmp() functions return an integer less than, equal to, or greater than zero if s1 (or the first n bytes thereof) is found, respectively, to be less than, to match, or be greater than s2.

    This would normally be implemented like @hroptatyr describes.

提交回复
热议问题