C Programming Code Examples C > Strings Code Examples Find the Frequency of Substring in the given String Find the Frequency of Substring in the given String 1. Take a string and a substring as input and store it in the arrays str[] and str1[] respectively. 2. Using for loop compare str1[] with the str[]. 3. Do step-2 until the end of the main string. 4. During the comparison increment the variable count whenever the substring matches in the main string. 5. Print the variable count as output. #include <stdio.h> #include <string.h> void main() { int count = 0, x, j = 0, k; char str[88], str1[8]; printf("Enter the string\n"); scanf(" %[^\n]s", str); printf("Enter the substring to be matched\n"); scanf(" %[^\n]s", str1); k = strlen(str1); for (x = 0;str[x] != '\0';) { if (str[x] == ' ') { x++; } else { if (str[x] == str1[j]) { j++; x++; } else if (j == k) { j = 0; count++; x--; } else { x++; j = 0; } } } printf("No of matches of substring in main string is %d\n", count); }