Tuesday 11 December 2012

Implement strncpy


/*This function will copy "n" character of the source string "src" to the target string "tar" and return Zero.*/

char *mystrncpy(char *tar, const char *src, int n)

{

char *t = tar; /*for Retaing the address tar string*/

/*Copying string*/

while(*src != '\0' && (*tar++ = *src++) && n--);

*tar = '\0';

return t;

}

No comments:

Post a Comment