Hi, I'have been fighting with this function all night and I can't figure out what's wrong with it.
here is my function:
Code:
char *cat(char *dest, char *src)
{
int j = strl(dest);
int i;
i = 0;
while (src[i])
{
dest[i + j] = src[i];
i++;
}
dest[i + j] = 0;
return (dest + i +j);
}
The idea is simple, kind of like strlcat, we take as inputs a destination and a source .
We paste the source at the first \0 of dest and then (this is were the problems start) we return the end of the pasted source so that we can keep on concatenating string.
for some reason if I do a printf of the returned string inside the function everything is fine but if I try to printf it outside the function I get a seg fault.
If you have any idea on what is wrong or can show me the way you solved this problem, please let me know.
Any help is very much appriciated, thanks for your time.