I need to check if a string is contained in another and returns the position where the first letter appeared.
I saw the following code here on the site, however I can not use the string.h
library.
include stdio.h
include string.h
int main()
{
char s1[20];
char s2[20];
printf("Digite uma string : ");
scanf("%s", s1);
printf("Digite outra string : ");
scanf("%s", s2);
printf("%ld", strstr(s1, s2) - s1);
}
I tried to do it as follows:
void str_conteudo( char str1[], char str2[])
{
int i=0;
int y;
while(str1[i] == str2[i] && str2[i] != 0)
{
if (str2[i] != str1[i])
return i;
i++;
}
y=i;
printf("Indice do primeiro caractere que contem a string 2: %d ", y);
}
But it is not increasing, what can be wrong?