标准C语言中的
size_t? strlen(chonst char* p);//p 的长度不计结束符。typedef unsigned int size_t; 也就是说size_t 就是unsigned int 类型。
而VC++6.0 中的strlen()返回值为int型:
用VC++ 6.0 编程时,如果加了#include
/*习题2.26
开发环境VC++6.0*/
#include
#include
int strLonger(char*,char*);
void main(){
?char *s = "d";
?char *t = "Id";
?printf("%d\n",strLonger(s,t));
}
int strLonger(char *s, char *t){
?return strlen(s) - strlen(t) > 0; //在C语言中,当一个无符号数和一个有符号数进行比较运算时,有符号数会被隐含地转换成无符号数,并假设这两个数都是非负数,然后进行比较运算。
}
//输出结果为 1
#includeint strLonger(char*,char*);
void main(){
?char *s = "d";
?char *t = "Id";?printf("%d\n",strLonger(s,t));
}int strLonger(char *s, char *t){
?return strlen(s) - strlen(t) > 0;
}
//输出结果为 0