统计字符串的个数

来源:互联网 发布:java字符串拼接工具类 编辑:程序博客网 时间:2024/06/06 11:45
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>#include <string.h> int statisticString(char *str,const char *findStr){if (NULL == str){return -1;}int num = 0;char *p = str;while (1){p = strstr(p, findStr);if (p == NULL){return num;}p += strlen(findStr);num++;}return num;} void test() { char *p = "asdsffgacd.,g.f,.fg,  abcwwacdw"; char *findStr = "wac"; int num = statisticString(p, findStr); printf("%d ",num); }void main(){test();system("pause");}

0 0
原创粉丝点击