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 is late binding c++?

748


How does work in c++?

845


What are pointer-to-members? Explain.

826


Is swift faster than go?

903


What is the object serialization?

869


Why c++ is called oop?

877


Write a Program for read a line from file from location N1 to N2 using command line arguments. Eg:exe 10 20 a.c

1054


What is ios in c++?

942


Will a recursive function without an end condition every quit, in practice a) Compiler-Specific (Some can convert to an infinite loop) b) No c) Yes

850


What is else syntax in c++?

872


What are the five basic elements of a c++ program?

856


Can we use this pointer inside static member function?

840


What is lambda expression c++?

787


Who was the creator of c++?

789


What are the advantages of using const reference arguments in a function?

861