Puedes crearte una función que recorra la cadena utilizando
strstr para contabilizar las veces que aparece la secuencia o subcadena especificada.
Ejemplo:
Código C:
Ver original#include <string.h>
#include <stdio.h>
int strstr_counter(const char* s1, const char* s2){
int match = 0;
while(pch != NULL){
pch
= strstr(s1
= pch
+ len
, s2
); match++;
}
return match;
}
int main(){
printf("%d\n", strstr_counter
("aaaaabbaaaaabbaaaabbaaa", "bb")); printf("%d\n", strstr_counter
("aaaaabbaaaaabbaaaabbaaa", "a")); printf("%d\n", strstr_counter
("aaaaabbaaaaabbaaaabbaaa", "aaaaa")); printf("%d\n", strstr_counter
("aaaaabbaaaaabbaaaabbaaa", "b")); printf("%d\n", strstr_counter
("aaaaabbaaaaabbaaaabbaaa", "dd"));
return 0;
}