2
I need to create a function that deletes in s1
the first occurrence of s2
.
char *StrlDelStr(char *s1,char *s2)
Example:
char *s = "O rato roeu a rolha da garrafa";
StrlDelStr(s, "xy"); -> "O rato roeu a rolha da garrafa"
StrlDelStr(s, "ra"); -> "O to roeu a rolha da garrafa"
My code is like this:
char *StrlDelStr(char *s1,char *s2)
{
int i, j;
for(i = 0, j = 0; i < strlen(s1); i++)
{
for(j = 0; j < strlen(s1); j++)
{
if(s1[i] == s2[j])
s1[i] = ' ';
}
}
return s1;
}
int main()
{
char palavras[100] = "Hello World";
char palavra2[100] = "lo";
StrlDelStr(palavras, palavra2);
printf("\n%s\n", palavras);
return 0;
}
Is exhibiting "He W r d"
. I need a function where instead of replacing it with ' '
all occurrences of character/string, just erase
where the string specific (s2
).
Your search for the second string is wrong. Also after locating the second string in the first you don’t have to replace it with space but move as many positions as the string total provided in the second parameter.
– anonimo