0
点赞
收藏
分享

微信扫一扫

【C 语言练习】判断子串个数?

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define L 50
#define l 5

int main()
{
int i, j, sLen, subStrLen;
char s[L] = "abcdefabcjkabcabc";
char subStr[l] = "abc";
// scanf("%s%s", s, subStr);
// printf("%s\n%s\n", s, subStr);
// printf("%d\n%d\n", strlen(s), strlen(subStr));
i = j = 0;
int c = 0;
while(i < strlen(s))
{
while(s[i++] != subStr[0] && i < strlen(s));
i -= 1;
if(s[i] == subStr[0])
{
while(s[i++] == subStr[j++] && i < strlen(s) && j < strlen(subStr));
if(j == strlen(subStr))
{
c += 1;
}
j = 0;
}
}
printf("%d\n", c);
return 0;
}


举报

相关推荐

0 条评论