字符串处理系列:输入任何一串字符串,计算其中ABC子字符串的个数

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012369580/article/details/44514841
#include<cstring>
#include<iostream>
using namespace std;
int coutABC(char *s)
{
char *sub = "ABC";
char *teststr=s;
int cnt = 0;
char *p = teststr;
while (*p)
{
if (strncmp(p, sub, 3) == 0)
{
p += 3;
cnt++;
}
else
p++;
}
return cnt;
}
int main()
{
char checkstr[100];
cout << "请输入字符串" << endl;
cin.getline(checkstr, 80);
cout << "ABC的个数: " << coutABC(checkstr) << endl;
return 0;
}

猜你喜欢

转载自blog.csdn.net/u012369580/article/details/44514841