This topic has been archived. It cannot be replied.
-
工作学习 / IT技术讨论 / 请DX 帮我看看这段c程序:
char a[3],b[5]="asdf";
memset(a,'\0',3);
if (strstr(b,a) !=NULL)
printf("a is in b!");
else
printf("a is not in b!");
为什么result is:a is in b!? 怎样才能既清空a有不让a in b?Thks
-volunteer(angel);
2004-11-27
(#2002289@0)
-
In the man page of strstr( S1, S2), it says: " If S2 points to a string with zero length, the S1 is returned"
-aka(棒棒);
2004-11-27
(#2002414@0)
-
请问怎样可以解决这个问题呢?
-volunteer(angel);
2004-11-27
(#2002591@0)
-
i dont see any thing wrong here, but if you need you can check the length put extra logic before you strstr.
-aka(棒棒);
2004-11-28
(#2002717@0)
-
a="\0\0\0", b="asdf". As length of a is 0, b is returned. b is not null, so "a is in b".
-orange0(桔子);
2004-11-28
(#2002722@0)
-
Mathematically, it is true that any set contain the empty set. If you do want to break this rule, the only suggestion is to create your own logic. It seems I am mean, because I just no idea why u r thinking in this way.
-elecskunk(elecskunk);
2004-11-28
(#2003058@0)
-
u just declare the pointer a. u didnot allocate space of a. so, you don't know the value is in a. compare them is meaningless.
-647i(盲人协会);
2004-11-28
(#2003078@0)
-
my mistake.
-647i(盲人协会);
2004-11-28
(#2003086@0)