C语言笔试题(3)——查找子串出现的次数

#include 
#include 

int count_str(char *str, char *s)
{
       char *s1, *s2;
       int count = 0;
       
        while(*str != '\0')
        {
               s1 = str;
               s2 = s;

               while(*s1 == *s3 && *s1 != '\0' && *s2!= '\0')
               {
                       s1++;
                       s2++;         
               } 

                if(*s2 == '\0')
                {
                       count++;
                } 
               
                 str ++;

        }

         return count;
}

int main(void)
{
       char *str = "hehehellfdfdfhehe";
       char *s = "he";

        count = count_str(str, s);
        printf("count: %d\n", count);

       return 0 ;
}


你可能感兴趣的:(C/C++笔试题)