I have two variables:
char s1[20];
char s2[20];
I will get the input of the user of the two variables, and after that, I need to check if s1
is contained in s2
, even a single part of it. For this I will use a function called esta_contido()
that will do this check.
Example:
s1 = "algoritmo";
s2 = "ritmo";
esta_contido(); retorna 4 --> pois ele retorna a primeira posição do caractere em que está contido.
My code:
char s1[20];
char s2[20];
void esta_contido() {
printf("Digite uma string : ");
scanf("%s",&s1);
printf("Digite outra string : ");
scanf("%s",&s2);
if (strstr(s1, s2) != NULL) {
for(int i = 0; i < 20; i++) {
if(s2[i] == s1[i]) {
i = 20;
printf("s2 : %s", &s2);
}
}
}
}
int main() {
setlocale(LC_ALL,"portuguese");
esta_contido();
}
In the part of if
with for
I'm checking if s1
and s2
has some equal parts, if they have pro forma, to check which words are equal, after that it gives output
pro user the words that are the same. In this I have already made some progress, but I need to give output
to the user not the letters, but the initial position in which is contained the string .