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 are different types of loops in c++?

664


Explain how an exception handler is defined and invoked in a Program.

590


Is empty stack c++?

525


What is the outcome of cout< a) 16 b) 17 c) 16.5

629


By using c++ with an example describe linked list?

609






If I is an integer variable, which is faster ++i or i++?

600


How are the features of c++ different from c?

604


what do you mean by volatile variable?

595


Is eclipse good for c++?

544


What flag means?

528


Why c++ is faster than java?

602


How do you initialize a string in c++?

568


State two differences between C and C++.

614


What are friend functions in C++?

631


Explain the differences between list x; & list x();.

610