C语⾔中strcmp函数返回值问题
关于strcmp这个函数标准时这样规定的:
int strcmp ( const char * str1, const char * str2 );
Compare two strings
Compares the C string str1 to the C string str2.
This function starts comparing the first character of each string. If they are equal to each other, it continues with the following pairs until the characters differ or until a terminating null-character is reached.
Parameters
str1
C string to be compared.
str2
C string to be compared.
Return Value
Returns an integral value indicating the relationship between the strings:
A zero value indicates that both strings are equal.
c++中string的用法A value greater than zero indicates that the first character that does not match has a greater value in str1 than in str2; And a value less than zero indicates the opposite.
在VC中strcmp("123","1234") 返回-1,⽽在TC中返回-52。
标准只是规定三个值:⼩于零,零,⼤于零。具体是什么值编译器⾃⼰定的,所以编程时候判断⼩于等于⼤于,不能判断是否等于1或者-1
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论