Implement strncpy

Answer Posted / ada

char *my_strncpy( char *dst, char *src, size_t n)
{
int i = n;
char *p = dst;

if(!dst || !src)
return dst;

while( i != 0 && *src != '\0' )
{
*p++ = *src++;
i --;
}

while( i!=0 )
{
*p++ = '\0';
i --;
}

return dst;
}

Is This Answer Correct ?    6 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What do you mean by persistent and non persistent objects?

740


Distinguish between new and malloc and delete and free().

575


Which is better c++ or java?

566


What is the difference between structure and class?

562


Does c++ support exception handling?

598






what are the types of Member Functions?

615


Define Virtual function in C++.

625


What is an object in c++?

614


What is the difference between global variables and local variable

538


How did c++ get its name?

575


Difference between a homogeneous and a heterogeneous container

661


What is the use of pointer in c++ with example?

563


What does the ios::ate argument do?

665


What is :: operator in c++?

580


How compile and run c++ program in turbo c++?

631