feat(str/strncpy): adding the function strncpy
- strncpy allowed to copy a string into an other with a limitation fix
This commit is contained in:
parent
905ffd4b72
commit
1dcd4f5b09
2 changed files with 38 additions and 1 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/31 15:04:59 by rparodi #+# #+# */
|
||||
/* Updated: 2025/09/01 17:56:24 by rparodi ### ########.fr */
|
||||
/* Updated: 2025/09/01 18:47:05 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -21,6 +21,7 @@ char *ft_strcpy(char *dst, const char *src);
|
|||
char *ft_strdup(const char *s);
|
||||
char *ft_strjoin(char const *s1, char const *s2);
|
||||
char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
|
||||
char *ft_strncpy(char *dst, const char *src, size_t size);
|
||||
char *ft_strnstr(const char *big, const char *little, size_t len);
|
||||
char *ft_strrchr(const char *s, int c);
|
||||
char *ft_strtrim(char const *s1, char const *set);
|
||||
|
|
|
|||
36
str/ft_strncpy.c
Normal file
36
str/ft_strncpy.c
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strncpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/31 16:14:10 by rparodi #+# #+# */
|
||||
/* Updated: 2025/09/01 18:46:55 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
/**
|
||||
* @brief Copies a string.
|
||||
*
|
||||
* @param dst The destination buffer.
|
||||
* @param src The source string.
|
||||
* @param size The size to copy
|
||||
*
|
||||
* @return A pointer to `dst`.
|
||||
*/
|
||||
char *ft_strcpy(char *dst, const char *src, size_t size)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (src[i] || i < size)
|
||||
{
|
||||
dst[i] = src[i];
|
||||
i++;
|
||||
}
|
||||
dst[i] = '\0';
|
||||
return (dst);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue