#include<stdio.h> #include<stdlib.h> #include<string.h> int main(void) { char palavra[5], frase[50]; printf("\nDigite a palavra: "); gets(palavra); printf("\nDigite a frase: "); gets(frase); int i, j, ocorre, numOcorrencias = 0; for (i=0; i<strlen(frase)-strlen(palavra)+1; i++) { if (frase[i]==palavra[0]) { j = 1; ocorre = 1; while (j<strlen(palavra) && ocorre) { if (palavra[j]==frase[i+j]) j++; else ocorre = 0; } if (ocorre) numOcorrencias++; } } printf("\nA palavra ocorre %d vezes na frase\n", numOcorrencias); system("pause"); return 0; }