answersLogoWhite

0

AllQ&AStudy Guides
Best answer

Using strcpy and strcat. Or sprintf. Or strlen+memcpy. There are more than solutions.

This answer is:
Related answers

Using strcpy and strcat. Or sprintf. Or strlen+memcpy. There are more than solutions.

View page

They do different things, so they are uncomparable.

PS: strcpy can be implemented with strlen+memcpy:

char *strcpy (char *dest, const char *src)

{

size_t len;

len= strlen (src);

memcpy (dest, src, len);

return dest;

}

View page

In short, you don't. strncpy is deemed unsafe as it has potential to cause buffer overruns. To copy strings safely in C++, use std::string instead.

For examples and syntax, see related links, below.

View page

strcpy

View page

char* strcpy(const char* src, char* dst) { char* tmp = dst; while ((*dst++ = *src++) != '\0'); return tmp; }

View page
Featured study guide
📓
See all Study Guides
✍️
Create a Study Guide
Search results