在运行下面的代码时,我看到,该 "x,y"模式发生了.这种模式印在这里:printf("%s", start);.但是 if (strncmp(cp, VAL, strlen(VAL) == 0 ))没有介入.我期待,它应该介入.有什么问题?
me@host ~ $ ./test|grep x,y
<P k="x,y" v="160.59" z="100"/>
Run Code Online (Sandbox Code Playgroud)
这是代码的一部分:
#define VAL "\"x,y\""
void process(char * start, char *stop)
{
char * cp;
printf("process\n");
printf("%s", start);
for (cp = start; cp <= stop; cp++)
{
if (strncmp(cp, VAL, strlen(VAL) == 0 ))
{
printf ("F O U N D VAL\n");
}
Run Code Online (Sandbox Code Playgroud)
}
也许你的意思
if (strncmp(cp, VAL, strlen(VAL)) == 0)
Run Code Online (Sandbox Code Playgroud)
相反
if (strncmp(cp, VAL, strlen(VAL) == 0 ))
Run Code Online (Sandbox Code Playgroud)
它基本上检查0字符,返回0,所以条件总是如此false.
| 归档时间: |
|
| 查看次数: |
81 次 |
| 最近记录: |