字符串查找操作出错

时间:2017-04-06 18:21:18

标签: c c-strings post-increment double-pointer

试图找出警告信息中是否存在PIR然后采取行动,但我不理解声明中的行为......

#include <stdio.h>
#include <stdlib.h>

int main() {
    char *a="Intrusion detected PIR Sensor";//warning message
    char **p=&a,**x;
    char *b="PIR";//string check
    char *c=b;
    int count1=0,count2=0;
    while(*c++)//count the size of string 
        count1++;

    for( ;**p;p++)//check for the occurrence of string in warning msg
    {
        x=p;
        while((*b++)==(**x++))
            count2++;
    }
    if(count1==count2)
        printf("Success\n");
    else
        printf("Failure\n");

    return 0;
}

0 个答案:

没有答案