C字符串对比问题 急!!!!!!

popMod 2010-12-17 02:01:12
代码是linux下的C
这个是声明:

UINT8 iManageId[11];
UINT8 iPdaIP[16];
typedef struct {
UINT8 PdaID[11];
UINT8 PdaIP[16];
}INIPDAPara;


这个是比对函数:
(strncmp((char *)(gINIPDAPara[j].PdaID),(char *)iManageId,10)==0)

打印的gINIPDAPara[j].PdaID为4527189后面不带空格
iManageId为4527188 后面有3个空格
为什么比出来的结果是相同了?
求指点
...全文
109 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
李万鹏 2010-12-17
  • 打赏
  • 举报
回复
接分~
popMod 2010-12-17
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 luciferisnotsatan 的回复:]
int strncmp(
const char *string1,
const char *string2,
size_t count
);


< 0
string1 substring less than string2 substring

0
string1 substring identical to string2 substring

……
[/Quote]
恩 谢谢了。 我知道问题所在了
luciferisnotsatan 2010-12-17
  • 打赏
  • 举报
回复

int strncmp(
const char *string1,
const char *string2,
size_t count
);


< 0
string1 substring less than string2 substring

0
string1 substring identical to string2 substring

> 0
string1 substring greater than string2 substring


strncmp返回值的含义,难道楼主把返回值当BOOL型的ture or false了?
luciferisnotsatan 2010-12-17
  • 打赏
  • 举报
回复
char iManageId[11] = "4527188";
char iPdaIP[16] = "4527188 ";
if (0==strncmp(iManageId,iPdaIP,10))
printf("==");
else
printf("!=");

输出为 !=

是你代码有问题吧,strncmp函数没问题
popMod 2010-12-17
  • 打赏
  • 举报
回复
恩 好像有点明白了。。。才开始用这个C 头大
昵称很不好取 2010-12-17
  • 打赏
  • 举报
回复
不用怀疑函数的用法,应该是程序中什么地方出错了,去查查程序吧,别在这纠结了
NowDoIT 2010-12-17
  • 打赏
  • 举报
回复

char *str1 = "abc";
char *str2 = "abc";

if(strncmp(str1,str2,3) == 0)
{
printf("str1 = %d\n",str1);
printf("str2 = %d\n",str2);
getch();
exit(0);
}


不是很懂楼主意思,不知楼主懂我的意思不?
panasonic0804 2010-12-17
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 popmod 的回复:]
引用 1 楼 panasonic0804 的回复:
因为gINIPDAPara[j].PdaID和iManageId代表的是字符串所在的位置(起始内存地址)


========================================================================
那该怎么弄呢?
[/Quote]
怎么弄?什么意思?
strncmp比较的gINIPDAPara[j].PdaID和iManageId所指向的字符串
popMod 2010-12-17
  • 打赏
  • 举报
回复
哪个大虾可以给个正确的方法?来对这2个数组进行对比?
在线等
popMod 2010-12-17
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 panasonic0804 的回复:]
因为gINIPDAPara[j].PdaID和iManageId代表的是字符串所在的位置(起始内存地址)
[/Quote]

========================================================================
那该怎么弄呢?
panasonic0804 2010-12-17
  • 打赏
  • 举报
回复
因为gINIPDAPara[j].PdaID和iManageId代表的是字符串所在的位置(起始内存地址)

69,369

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧