C 语言中strcmp函数返回值问题
(2012-07-17 10:22:05)
标签:
it |
分类: 讲解 |
关于strcmp这个函数标准时这样规定的:
int strcmp ( const char * str1, const char * str2 );
Compare two strings
Compares the C string
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.
A value greater than zero indicates that the first character that
does not match has a greater value in
在VC中strcmp("123","1234") 返回-1,而在TC中返回-52。
标准只是规定三个值:小于零,零,大于零。具体是什么值编译器自己定的,所以编程时候判断小于等于大于,不能判断是否等于1或者-1

加载中…