I'm trying to make a function which deletes l elements, starting from the k position. My function returns another set of chars after deleting the chars. String_length is a function which returns the length of the string.
Remove Chars
char * remove_chars(char s1[], int k, int l)
{
int j = 0;
if(string_length(s1) + 1 < k || string_length(s1) + 1 < l)
return 0;
else
{
char s2[100];
for(int i = 0; s1[i] != '\0'; ++i)
{
if((i <= k - 1) || (i > k + l - 1 ))
{
s2[j] = s1[i];
++j;
}
}
s2[j] = '\0';
return s2;
}
}
The problem is, that after I call the remove_chars function in main, it returns as null, but when I try to print s2 inside remove_chars function, it prints it out just like it was supposed to be.