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

How do you declare A pointer to a function which receives nothing and returns nothing

1218


Who was the creator of c++?

1033


What's c++ used for?

1098


Explain about vectors in c ++?

1010


What new()is different from malloc()?

1088


What data structure is fastest, on average, for retrieving data: a) Binary Tree b) Hash Table c) Stack

1067


Why is c++ awesome?

1020


Differentiate between late binding and early binding.

1258


What is iterator in c++?

1093


Write a program which uses Command Line Arguments

1164


How do you find out if a linked-list has an end? (I.e. The list is not a cycle)

1147


Using a smart pointer can we iterate through a container?

1060


Describe linked list using C++ with an example.

1071


Is there structure in c++?

1011


What is the difference between prefix and postfix versions of operator++()?

1069