Substring Finder
C
Medium
3 views
Problem Description
Perform a substring search in a string. Implement strstr() without manually doing it. Count matching characters and return them.
Official Solution
#include <stdio.h>
int main() {
char str[200], sub[100];
int i, j;
int mainLen = 0, subLen = 0;
int matchCount = 0;
int found = 0;
printf("Enter main string: ");
fgets(str, sizeof(str), stdin);
printf("Enter substring to search: ");
fgets(sub, sizeof(sub), stdin);
// Remove newline characters if present
for (i = 0; str[i] != '