Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

Commit

Permalink
substr
Browse files Browse the repository at this point in the history
  • Loading branch information
nopbxlr committed May 9, 2022
1 parent b97351f commit dd59979
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
4 changes: 2 additions & 2 deletions ft_itoa.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: ctherin <ctherin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/09 16:58:14 by ctherin #+# #+# */
/* Updated: 2022/05/09 17:22:48 by ctherin ### ########.fr */
/* Updated: 2022/05/09 17:34:10 by ctherin ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -44,7 +44,7 @@ char *ft_itoa(int n)

nb_len = get_nb_len(n);
nl = n;
ptr = ft_calloc(nb_len, sizeof(char));
ptr = ft_calloc(nb_len + 1, sizeof(char));
if (!ptr)
return (NULL);
if (nl < 0)
Expand Down
32 changes: 32 additions & 0 deletions ft_substr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ctherin <ctherin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/09 17:31:48 by ctherin #+# #+# */
/* Updated: 2022/05/09 17:39:42 by ctherin ### ########.fr */
/* */
/* ************************************************************************** */

#include"libft.h"

char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *ptr;
size_t i;
char *d;

i = 0;
d = (char *)s;
ptr = ft_calloc(len + 1, sizeof(char));
if (!ptr)
return (ptr);
while (i < len && d[start + i])
{
ptr[i] = d[i + start];
i++;
}
return (ptr);
}
3 changes: 2 additions & 1 deletion libft.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: ctherin <ctherin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/02 17:49:13 by ctherin #+# #+# */
/* Updated: 2022/05/09 17:21:37 by ctherin ### ########.fr */
/* Updated: 2022/05/09 17:39:03 by ctherin ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -44,5 +44,6 @@ int ft_atoi(const char *nptr);
char *ft_strjoin(char const *s1, char const *s2);
char **ft_split(const char *s, char c);
char *ft_itoa(int n);
char *ft_substr(char const *s, unsigned int start, size_t len);

#endif

0 comments on commit dd59979

Please sign in to comment.