fork download
  1. #include <stdio.h>
  2.  
  3. int str_conteudo( char str1[], char str2[]) {
  4. int i=0,j,k;
  5. for(i = 0; str1[i] != '\0'; ++i) {
  6. for (j = i,k = 0;str1[j]!= '\0' && str2[k] != '\0' && str1[j] == str2[k]; ++j,k++);
  7. if (str2[k] == '\0'){
  8. return i;
  9. }
  10. }
  11. return -1;
  12. }
  13.  
  14. int main(int argc, char *argv[]) {
  15.  
  16. printf("%d\n", str_conteudo ("Frase de teste","de"));
  17. printf("%d\n", str_conteudo ("Frase de teste","teste"));
  18. printf("%d\n", str_conteudo ("Frase de teste","Frase"));
  19. printf("%d\n", str_conteudo ("Frase de teste","cuFra"));
  20. printf("%d\n", str_conteudo ("Frase de teste","testem"));
  21.  
  22. return 0;
  23. }
  24.  
Success #stdin #stdout 0s 4384KB
stdin
Standard input is empty
stdout
6
9
0
-1
-1