天天看点

题目:计算字符串中子串出现的次数 提示:请使用scanf 函数输入2个字符串str1, str2 ,再计算字符串中子串出现的次数

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/*
	题目:计算字符串中子串出现的次数
	提示:请使用scanf 函数输入2个字符串str1, str2 ,再计算字符串中子串出现的次数

*/
int main()
{
	char str1[100];
	char str2[50];
	int m_count = 0;

	scanf("%s", str1);

	scanf("%s", str2);

	char* tmp = str1;

	while ((tmp = strstr(tmp, str2)) != NULL)
	{
		m_count++;
		tmp++;
	}

	printf("%d\n", m_count);


	return 0;
}