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

来源:互联网 发布:用什么表示增量编程 编辑:程序博客网 时间:2024/04/30 02:18
#include <stdio.h>#include <string.h>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 ;}


原创粉丝点击