Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

Implement strncpy

Answer Posted / lylez00

#include <string.h>
/* strncpy */
char *(strncpy)(char *restrict s1, const char *restrict s2,
size_t n)
{
char *dst = s1;
const char *src = s2;
/* Copy bytes, one at a time. */
while (n > 0) {
n--;
if ((*dst++ = *src++) == '\0') {
/* If we get here, we found a null character at
the end
of s2, so use memset to put null bytes at
the end of
s1. */
memset(dst, '\0', n);
break;
}
}
return s1;
}

Is This Answer Correct ?    1 Yes 5 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is function prototyping? What are its advantages?

1042


What is a class template?

1036


Do you know about C++ 11 standard?

1045


What are all predefined data types in c++?

1085


Is it possible for a member function to use delete this?

1031


What are friend classes? What are advantages of using friend classes?

1054


What is function overloading in C++?

1364


Why is main an int?

940


How a new operator differs from the operator new?

1068


What are the advantage of using register variables?

1127


Can you be bale to identify between straight- through and cross- over cable wiring? And in what case do you use straight- through and cross-over?

958


Which is not a valid keyword a) public b) protected c) guarded

1207


Why is c++ is better than c?

921


What are the 2 main types of data structures?

1080


What is buffer and example?

954