1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > C小程序——统计字符串中出现指定串abcd的次数

C小程序——统计字符串中出现指定串abcd的次数

时间:2019-07-24 11:27:59

相关推荐

C小程序——统计字符串中出现指定串abcd的次数

#include "stdio.h"

#include "string.h"

#include <stdlib.h>

//统计字符串中出现指定串abcd的次数

int main(int argc, char *argv[])

{

char *p = "abcd1234abcd54a655abcd333af33";

int ncount = 0;

do

{

p = strstr(p, "a"); //查找字符串中第一次出现指定串abcd的首位子

if (p == NULL)

{

break;

}

else

{

ncount++;

p = p + strlen("abcd");

}

}while(*p != '\0');

printf("ncout:%d\n", ncount);

return 0;

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。