any ideas about how to write a RECURSIVE function that gets 2 parameters :
first is an address d (a location of char).
second is a string.
The function copies the string s to a location starting at d.
The function returns d as a result !
can we do it without strcpy ?
copy_r(char *s, char *d)
{
*d = *s;
if(*s)return copy_r(++s, ++d);
}
where is the mistake ? (found )
put still there is a problem ! what if the location d overlaps some location that is already occupied by s ?
this for example
strcpy(p1, "abcdefghijklomopqrstuvwqyz"); printf(copy_r(p1, p1+10));doesnt work –
output should be klomopqrstuvwqyz
No comments:
Post a Comment