I have a problem writing the code to this problem and i can't seem to wrap my head around on how to do it. It's for my university assignment and I've tried a program that gives the same output but still says i got the wrong answer.
For example,
Input:
aabbaabbaacc
aa
Output:
3
here is my code:
#include <stdio.h>
#include <string.h>
int main()
{
char str[] = "aabbaaccaadd";
char substr[] = "aa";
char* ptr = strstr(str, substr);
int count = 0;
while (ptr != NULL) {
count++;
ptr = strstr(ptr + 1, substr);
{
printf("%d", count);
return 0;
}
}
}