C 语言中strcmp函数返回值问题

来源:互联网 发布:大连男科医院网络预约 编辑:程序博客网 时间:2024/05/17 03:54

关于strcmp这个函数标准时这样规定的:

 

int strcmp ( const char * str1, const char * str2 );

Compare twostrings

Compares the C string str1 to the Cstring str2.
This function starts comparing the first character of each string.If they are equal to each other, it continues with the followingpairs until the characters differ or until a terminatingnull-character is reached.

Parameters

str1 
C string to becompared. 
str2 
C string to becompared.

Return Value

Returns an integral value indicating the relationship between thestrings:
A zero value indicates that both strings are equal.
A value greater than zero indicates that the first character thatdoes not match has a greater value in str1 thanin str2; And a value less than zeroindicates the opposite.

 

在VC中strcmp("123","1234") 返回-1,而在TC中返回-52。

标准只是规定三个值:小于零,零,大于零。具体是什么值编译器自己定的,所以编程时候判断小于等于大于,不能判断是否等于1或者-1
原创粉丝点击