NetApp Interview Question
Software Engineer / Developersno need to keep from pointer , waste register.
what if abs(dest-src)<strlen(src)?
what if *dest is NULL?
char * mystrcpy(char * t, const char *s)
{
int size=strlen(s);
char *t1=t;
if(t==NULL) return NULL;
if((t-s<=strlen(s))||(s-t<=strlen(s))) return NULL;
while(*t++=*s++);
return t1;
}
The function needs to
1. Make sure that dest points to a valid memory address (for example, not null or 0) and
2. It has enough memory to hold all characters + null character from the source string.
3. There is no need to return anything. The function can be void if it is copying to the memory location passed via the argument.
- Anonymous March 23, 2011