Implement strncpy

Answer Posted / shanmugavalli

char* strncpy(char* dest,const char* src,int n)
{
while(n>0)
{
if (!(*dest = *src)) break;
src++;
dest++;
n--;
}
if (n<=0) *dest = '\0';
return dest;
}

Is This Answer Correct ?    3 Yes 4 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


Explain "const" reference arguments in function?

615


How new/delete differs from malloc()/free?

617


Explain what are mutator methods in c++?

572


What is a constructor in c++ with example?

580






What are advantages of c++?

562


Is c++ vector dynamic?

574


What is c++ try block?

582


If you hear the cpu fan is running and the monitor power is still on, but you did not see anything show up in the monitor screen. What would you do to find out what is going wrong?

551


Do you know what are static and dynamic type checking?

620


Which operator cannot overload?

543


Explain the different access specifiers for the class member in c++.

548


What is the purpose of ios::basefield in the following statement?

790


What is oops in c++?

591


Explain shallow copy?

612