c语言代码实现:

此处)折叠或打开

1. #include<stdio.h>
2. <string.h>
3. int searchnum(char *str,char *pattern)
4. {
5. if (str == NULL)
6. ;
7. *pos = NULL;
8. int count = 0;
9. while ((pos = strstr(str,pattern)) != NULL)
10. {
11. ++;
12. += (strlen(pattern));
13. = pos;
14. //        count = count+1;
15. }
16. ;
17. }
18. int main()
19. {
20. *str = "world hello world word world";
21. ("%d\n",searchnum(str,"world"));
22. ;
23. }

运行结果:


[root@localhost ~]# ./a.out


3