Question #5906   Submitted by Answiki on 02/23/2022 at 07:26:19 AM UTC

How to use the strlcpy function in C ?

Answer   Submitted by Answiki on 02/23/2022 at 07:29:51 AM UTC

The strlcpy function copy a string into another string by limiting the number of copied characters. The prototype is:

size_t strlcpy(char *dst, const char *src, size_t size);


  • The first parameter is the destination string (dst = destination)
  • The second parameter is the string to copy (src = source)
  • The third parameter is the number of characters to copy (size)


To use the strlcpy function, you have to include the bsd/string.h library:

#include <bsd/string.h>


Note that strlcpy is not a standard C function, while strncpy belongs to string.h.


2 events in history
Answer by Answiki on 02/23/2022 at 07:29:51 AM

The strlcpy function copy a string into another string by limiting the number of copied characters. The prototype is:

size_t strlcpy(char *dst, const char *src, size_t size);


  • The first parameter is the destination string (dst = destination)
  • The second parameter is the string to copy (src = source)
  • The third parameter is the number of characters to copy (size)


To use the strlcpy function, you have to include the bsd/string.h library:

#include <bsd/string.h>


Note that strlcpy is not a standard C function, while strncpy belongs to string.h.


Question by Answiki 02/23/2022 at 07:26:19 AM
How to use the strlcpy function in C ?
# ID Query URL Count

Icons proudly provided by Friconix.