#include<stdio.h>


int count_substr(char *str, char *substr)
{
    int count = 0;
    char *p = substr;
    
    while(*str != '\0')
    {
        while( *p != '\0')
        {
            if( *(str++) != *(p++) )
            {
                if( *(str-1) == substr[0] && *str == substr[1])
                    str = str - 1;        
                break;
            }
            
            if ( *p == '\0') 
                count = count + 1;
        }
        
        p = substr;
    }
    return count;
}

int main()
{
    char *str = "wdxdsdfasdfxwdddxddwddxwdxxxx";
    char *substr = "wdx";
    int i = count_substr(str, substr);
    printf("%d\n",i);

}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-15
  • 2021-08-20
  • 2021-11-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-02-15
  • 2022-12-23
  • 2021-11-06
  • 2022-12-23
  • 2021-07-09
  • 2021-11-29
  • 2022-12-23
相关资源
相似解决方案