C applet - count the number of times the specified string abcd appears in the string

#include "stdio.h"

#include "string.h"

#include <stdlib.h>


// Count the number of times the specified string abcd appears in the string

int main(int argc, char *argv[])

{

    char *p = "abcd1234abcd54a655abcd333af33";

    int ncount = 0;

    

    do

    {

        p = strstr (p, "a" ); // find the first occurrence of the specified string abcd in the string

        if (p == NULL)

        {

            break;

        }

        else

        {

            ncount++;

            p = p + strlen("abcd");

        }

        

    }while(*p != '\0');

    printf("ncout:%d\n", ncount);

    return0;

    

}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325809683&siteId=291194637