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

Answers were Sorted based on User's Feedback



Implement strncpy..

Answer / 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

Implement strncpy..

Answer / 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

Implement strncpy..

Answer / 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

More C++ General Interview Questions

What is do..while loops structure?

0 Answers  


how many trys can we write in one class

3 Answers   Cap Gemini,


Which one between if-else and switch is more efficient?

0 Answers  


Give 10 points of differences between C & C++.

0 Answers   HCL,


write the prime no program in c++?

16 Answers  


What is exception handling? Does c++ support exception handling?

0 Answers  


What are multiple inheritances (virtual inheritance)?

0 Answers  


what is meaning of isa and hsa

1 Answers  


what are the decision making statements in C++? Explain if statement with an example?

0 Answers  


What is an adaptor class in c++?

0 Answers  


Write about the use of the virtual destructor?

0 Answers  


What is an Iterator class?

1 Answers  


Categories