#include <stdio.h>
void str_conteudo( char str1[ ] , char str2[ ] ) {
int i= 0 , j, k;
int y = - 1 ;
while ( str1[ i] != '\0 ' ) {
if ( str2[ 0 ] == str1[ i] ) {
for ( j = i+ 1 , k = 1 ; str1[ j] != '\0 ' && str2[ k] != '\0 ' && str1[ j] == str2[ k] ; ++ j, k++ ) ;
if ( str2[ k] == '\0 ' ) {
y = i;
break ;
}
}
i++;
}
if ( y>= 0 )
printf ( "Indice do primeiro caractere que contem a string 2: %d \n " , y
) ; else
printf ( "A string 2 nao esta contida na string 1. \n " ) ; }
int main( int argc, char * argv[ ] ) {
str_conteudo ( "Frase de teste" , "de" ) ;
str_conteudo ( "Frase de teste" , "teste" ) ;
str_conteudo ( "Frase de teste" , "Frase" ) ;
str_conteudo ( "Frase de teste" , "cuFra" ) ;
str_conteudo ( "Frase de teste" , "testem" ) ;
return 0 ;
}
I2luY2x1ZGUgPHN0ZGlvLmg+Cgp2b2lkIHN0cl9jb250ZXVkbyggY2hhciBzdHIxW10sIGNoYXIgc3RyMltdKSB7CglpbnQgaT0wLGosIGs7CglpbnQgeSA9IC0xOwoKCXdoaWxlKHN0cjFbaV0gIT0gJ1wwJykgewoJCWlmIChzdHIyWzBdID09IHN0cjFbaV0pIHsKCQkJZm9yIChqID0gaSsxLGsgPSAxO3N0cjFbal0hPSAnXDAnICYmIHN0cjJba10gIT0gJ1wwJyAmJiBzdHIxW2pdID09IHN0cjJba107ICsraixrKyspOwoKCQkJaWYgKHN0cjJba10gPT0gJ1wwJyl7CiAgICAgICAgICAgICAgICB5ID0gaTsKICAgICAgICAgICAgICAgIGJyZWFrOwoJCQl9CgkJfQoJCWkrKzsKCX0KCglpZih5Pj0wKQoJCXByaW50ZigiSW5kaWNlIGRvIHByaW1laXJvIGNhcmFjdGVyZSBxdWUgY29udGVtIGEgc3RyaW5nIDI6ICVkIFxuIiwgeSk7CgllbHNlCgkJcHJpbnRmKCJBIHN0cmluZyAyIG5hbyBlc3RhIGNvbnRpZGEgbmEgc3RyaW5nIDEuIFxuIik7Cn0KCmludCBtYWluKGludCBhcmdjLCBjaGFyICphcmd2W10pIHsKICAgIHN0cl9jb250ZXVkbyAoIkZyYXNlIGRlIHRlc3RlIiwiZGUiKTsKICAgIHN0cl9jb250ZXVkbyAoIkZyYXNlIGRlIHRlc3RlIiwidGVzdGUiKTsKICAgIHN0cl9jb250ZXVkbyAoIkZyYXNlIGRlIHRlc3RlIiwiRnJhc2UiKTsKICAgIHN0cl9jb250ZXVkbyAoIkZyYXNlIGRlIHRlc3RlIiwiY3VGcmEiKTsKICAgIHN0cl9jb250ZXVkbyAoIkZyYXNlIGRlIHRlc3RlIiwidGVzdGVtIik7CgoJcmV0dXJuIDA7Cn0K