- 论坛徽章:
- 0
|
本帖最后由 z32556601 于 2013-03-15 14:01 编辑
先上代码
#include <stdio.h>
#include <string.h>
int strcmp_fb(const char *cs, const char *ct);//把源码里的代码完全拷贝过来.
void main(){
char a[3] = {'k', 'o', 'b'};//我故意不以'\0'结尾.
//int b = strcmp("kob", a);
//printf("%d\n", b);
int x = strcmp_fb("kob", a);
printf("%d\n", x);
}
int strcmp_fb(const char *cs, const char *ct){//实现和源码一模一样
unsigned char c1, c2;
while (1) {
c1 = *cs++;
c2 = *ct++;
if (c1 != c2)
return c1 < c2 ? -1 : 1;
if (!c1)
break;
}
return 0;
}
我把源码里的strcmp代码一模一样的拷到strcmp_fb中.然后分别用同样的参数调用..
结果源码的结果是0.而复制的结果是-1.为什么... |
|