The strcpy() function and strncpy() function of C language

strcpy() function

<string.h>

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

parameter

dest – Points to the destination array where the copied content will be stored.

src – the string to copy.

Copy the string pointed to by src to dest.

It should be noted that if the destination array dest is not large enough and the length of the source string is too long, buffer overflow may occur.

Return Value: This function returns a pointer to the final destination string dest.

strncpy() function

<string.h>

char *strncpy(char *dest, const char *src, size_t n)

parameter

dest – Points to the destination array where the copied content will be stored.

src – the string to copy.

n – The number of characters to copy from the source.

Copy the string pointed to by src to dest, up to n characters. When the length of src is less than n, the remainder of dest will be filled with null bytes.

Return Value: The function returns the final copied string.

Guess you like

Origin blog.csdn.net/chengkai730/article/details/132397438