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

Commit

Permalink
strdup, toupper, tolower
Browse files Browse the repository at this point in the history
  • Loading branch information
nopbxlr committed May 4, 2022
1 parent 088b8b1 commit f9c7219
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 1 deletion.
5 changes: 4 additions & 1 deletion includes/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/04 20:45:45 by ctherin ### ########.fr */
/* Updated: 2022/05/04 21:11:16 by ctherin ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -32,5 +32,8 @@ void *ft_memccpy(void *dest, const void *src, int c, size_t n);
int ft_strncmp(const char *s1, const char *s2, size_t n);
char *ft_strnstr(const char *big, const char *little, size_t len);
int ft_memcmp(const void *s1, const void *s2, size_t n);
char *ft_strdup(const char *s);
int ft_toupper(int c);
int ft_tolower(int c);

#endif
33 changes: 33 additions & 0 deletions srcs/ft_strdup.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ctherin <ctherin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/04 21:04:57 by ctherin #+# #+# */
/* Updated: 2022/05/04 21:05:37 by ctherin ### ########.fr */
/* */
/* ************************************************************************** */

#include<stdlib.h>

char *ft_strdup(const char *s)
{
int sz;
int i;
char *dest;

sz = 0;
i = 0;
while (s[sz])
sz++;
dest = malloc (sizeof(char) * (sz + 1));
while (i < sz)
{
dest[i] = s[i];
i++;
}
dest[i] = '\0';
return (dest);
}
21 changes: 21 additions & 0 deletions srcs/ft_tolower.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_tolower.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ctherin <ctherin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/04 21:10:17 by ctherin #+# #+# */
/* Updated: 2022/05/04 21:10:40 by ctherin ### ########.fr */
/* */
/* ************************************************************************** */

int ft_tolower(int c)
{
unsigned char a;

a = (unsigned char)c;
if (a >= 'A' && a <= 'Z')
return (c + 32);
return (c);
}
21 changes: 21 additions & 0 deletions srcs/ft_toupper.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_toupper.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ctherin <ctherin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/04 21:07:38 by ctherin #+# #+# */
/* Updated: 2022/05/04 21:10:45 by ctherin ### ########.fr */
/* */
/* ************************************************************************** */

int ft_toupper(int c)
{
unsigned char a;

a = (unsigned char)c;
if (a >= 'a' && a <= 'z')
return (c - 32);
return (c);
}

0 comments on commit f9c7219

Please sign in to comment.