nouveau fichier : ft_atoi.c

nouveau fichier : ft_bzero.c
	nouveau fichier : ft_calloc.c
	nouveau fichier : ft_isalnum.c
	nouveau fichier : ft_isalpha.c
	nouveau fichier : ft_isascii.c
	nouveau fichier : ft_isdigit.c
	nouveau fichier : ft_isprint.c
	nouveau fichier : ft_memccpy.c
	nouveau fichier : ft_memchr.c
	nouveau fichier : ft_memcmp.c
	nouveau fichier : ft_memcpy.c
	nouveau fichier : ft_memmove.c
	nouveau fichier : ft_memset.c
	nouveau fichier : ft_strchr.c
	nouveau fichier : ft_strdup.c
	nouveau fichier : ft_strlcat.c
	nouveau fichier : ft_strlcpy.c
	nouveau fichier : ft_strlen.c
	nouveau fichier : ft_strncmp.c
	nouveau fichier : ft_strnstr.c
	nouveau fichier : ft_strrchr.c
	nouveau fichier : ft_tolower.c
	nouveau fichier : ft_toupper.c
This commit is contained in:
kinou 2020-11-29 21:28:02 +01:00
parent b94a3b6962
commit 78f458cfef
24 changed files with 664 additions and 0 deletions

39
ft_atoi.c Normal file
View File

@ -0,0 +1,39 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/29 00:09:17 by apommier #+# #+# */
/* Updated: 2020/11/29 17:02:15 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
int ft_atoi(const char *nptr)
{
int i;
int nbr;
int minus;
minus = 1;
nbr = 0;
i = 0;
while (nptr[i] == 32)
i++;
if (nptr[i] == '+')
i++;
else if (nptr[i] == '-')
{
i++;
minus = -1;
}
while (nptr[i] >= '0' && nptr[i] <= '9')
{
nbr = nbr * 10 + nptr[i] - '0';
i++;
}
return (minus * nbr);
}

28
ft_bzero.c Normal file
View File

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_bzero.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/29 00:09:48 by apommier #+# #+# */
/* Updated: 2020/11/29 17:02:33 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
void ft_bzero(void *s, size_t n)
{
char *p;
int i;
p = (char*)s;
i = 0;
while (n != 0)
{
p[i] = 0;
i++;
n--;
}
}

23
ft_calloc.c Normal file
View File

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/29 00:09:57 by apommier #+# #+# */
/* Updated: 2020/11/29 17:03:36 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
void *ft_calloc(size_t nmemb, size_t size)
{
void *tab;
tab = malloc(size * nmemb);
if (tab == 0)
return (0);
return (tab);
}

23
ft_isalnum.c Normal file
View File

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalnum.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/29 00:10:08 by apommier #+# #+# */
/* Updated: 2020/11/29 17:04:06 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
int ft_isalnum(int c)
{
if (c <= 9 && c >= 0)
return (c);
else if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'))
return (c);
else
return (0);
}

24
ft_isalpha.c Normal file
View File

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalpha.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/29 00:10:17 by apommier #+# #+# */
/* Updated: 2020/11/29 17:04:28 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
int ft_isalpha(int c)
{
char c;
ch = (char)c;
if ((c > 64 && c < 90) || (c > 96 && c < 122))
return (c);
else
return (0);
}

21
ft_isascii.c Normal file
View File

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isascii.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/29 00:10:30 by apommier #+# #+# */
/* Updated: 2020/11/29 17:04:48 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
int ft_isascii(int c)
{
if (c >= 0 && c <= 127)
return (c);
else
return (0);
}

21
ft_isdigit.c Normal file
View File

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isdigit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/29 00:10:39 by apommier #+# #+# */
/* Updated: 2020/11/29 17:05:09 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
int ft_isdigit(int c)
{
if (c <= 9 && c >= 0)
return (c);
else
return (0);
}

21
ft_isprint.c Normal file
View File

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isprint.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/29 00:10:55 by apommier #+# #+# */
/* Updated: 2020/11/29 17:05:23 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
int ft_isprint(int c)
{
if (c > 31 && c < 127)
return (c);
else
return (0);
}

35
ft_memccpy.c Normal file
View File

@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memccpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/29 00:11:04 by apommier #+# #+# */
/* Updated: 2020/11/29 16:57:52 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
void *ft_memccpy(void *dest, const void *src, int c, size_t n)
{
char *p;
char *p1;
p = (char*)dest;
p1 = (char*)src;
while (n > 0 && *p1 != c)
{
*p = *p1;
p++;
p1++;
n--;
}
if (*p1 == (char)c)
{
*p = *p1;
p++;
}
return ((void*)p);
}

27
ft_memchr.c Normal file
View File

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/29 00:11:39 by apommier #+# #+# */
/* Updated: 2020/11/29 17:05:45 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
void *ft_memchr(const void *s, int c, size_t n)
{
unsigned char *str;
str = (unsigned char*)s;
while (n)
{
if (c == *str)
return (str);
n--;
str++;
}
}

28
ft_memcmp.c Normal file
View File

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/29 00:11:51 by apommier #+# #+# */
/* Updated: 2020/11/29 17:05:58 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
int i;
i = 0;
while (n)
{
if (s1[i] != s2[i])
return (s1[i] - s2[i]);
n--;
i++;
}
return (0);
}

30
ft_memcpy.c Normal file
View File

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/29 00:12:03 by apommier #+# #+# */
/* Updated: 2020/11/29 17:06:29 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
void *ft_memcpy(void *dest, const void *src, size_t n)
{
unsigned char *p;
unsigned char *p2;
int i;
i = 0;
p = (char*)dest;
p2 = (char*)src;
while (n > 0)
{
n--;
p[i] = p2[i];
}
return (dest);
}

37
ft_memmove.c Normal file
View File

@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memmove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/29 00:12:14 by apommier #+# #+# */
/* Updated: 2020/11/29 17:07:14 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
void *ft_memmove(void *dest, const void *src, size_t n)
{
size_t i;
i = 0;
if (dest > src)
{
while (n)
{
((char*)dest)[n] = ((char*)src)[n];
n--;
}
}
else
{
while (i < n)
{
((char*)dest)[i] = ((char*)src)[i];
i++;
}
}
return (dest);
}

29
ft_memset.c Normal file
View File

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/29 00:12:24 by apommier #+# #+# */
/* Updated: 2020/11/29 17:08:00 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
void *ft_memset(void *s, int c, size_t n)
{
int i;
char *p;
i = 0;
p = (unsigned char*)s;
while (n > 0)
{
p[i] = (unsigned char)c;
i++;
n--;
}
return (s);
}

26
ft_strchr.c Normal file
View File

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/29 00:12:32 by apommier #+# #+# */
/* Updated: 2020/11/29 17:08:24 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
char *ft_strchr(const char *s, int c)
{
char *str;
str = s;
while ((*str != c) || (*str != 0))
str++;
if (*str == c)
return (str);
else
return (0);
}

33
ft_strdup.c Normal file
View File

@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/29 00:12:43 by apommier #+# #+# */
/* Updated: 2020/11/29 17:10:17 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
char *ft_strdup(const char *s)
{
int i;
char *sdup;
i = 0;
while (s[i])
i++;
sdup = malloc(sizeof(char) * i);
if (sdup == 0)
return (0);
i = 0;
while (s[i])
{
sdup[i] = s[i];
i++;
}
return (sdup);
}

30
ft_strlcat.c Normal file
View File

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/29 00:12:57 by apommier #+# #+# */
/* Updated: 2020/11/29 17:10:54 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
size_t ft_strlcat(char *dst, const char *src, size_t size)
{
int i;
int j;
j = 0;
i = ft_strlen(dst);
while (size - 1 - i)
{
dst[i] = src[j];
i++;
j++;
}
dst[i] = 0;
return (ft_strlen(dst) + ft_strlen(src));
}

32
ft_strlcpy.c Normal file
View File

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/29 00:13:07 by apommier #+# #+# */
/* Updated: 2020/11/29 17:11:24 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
size_t ft_strlcpy(char *dst, const char *src, size_t size)
{
int i;
int j;
j = 0;
i = 0;
while (scr[i])
i++;
while (size - 1 && src[j] != 0)
{
dst[j] = src[j];
j++;
size--;
}
dst[j] = 0;
return (i);
}

23
ft_strlen.c Normal file
View File

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/29 00:13:19 by apommier #+# #+# */
/* Updated: 2020/11/29 17:12:23 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
size_t ft_strlen(const char *s)
{
size_t i;
i = 0;
while (s[i] != 0)
i++;
return (i);
}

28
ft_strncmp.c Normal file
View File

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/29 00:13:31 by apommier #+# #+# */
/* Updated: 2020/11/29 17:14:21 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
int ft_strncmp(const char *s1, const char *s2, size_t n)
{
int i;
i = 0;
while (n && s1[i] && s2[i])
{
if (s1[i] != s2[i])
return ((unsigned char)(s1[i] - s2[i]));
n--;
i++;
}
return (0);
}

37
ft_strnstr.c Normal file
View File

@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/29 00:13:42 by apommier #+# #+# */
/* Updated: 2020/11/29 17:20:11 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
char *ft_strnstr(const char *big, const char *little, size_t len)
{
int i;
int j;
i = 0;
if (little[i] == 0)
return (big);
while (big[i] && len - i)
{
j = 0;
if (little[j] != big[i])
i++;
else
{
while (little[j] == big[i + j] && little[j] && len - i - j)
j++;
if (little[j] == 0)
return (&big[i]);
}
}
return (0);
}

29
ft_strrchr.c Normal file
View File

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strrchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/29 00:13:52 by apommier #+# #+# */
/* Updated: 2020/11/29 17:20:30 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
char *ft_strrchr(const char *s, int c)
{
char *str;
char *last;
last = 0;
str = s;
while (*str != 0)
{
if (*str == c)
last = str;
str++;
}
return (last);
}

20
ft_tolower.c Normal file
View File

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_tolower.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/29 00:14:05 by apommier #+# #+# */
/* Updated: 2020/11/29 17:20:51 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
int ft_tolower(int c)
{
if (c >= 65 && c <= 90)
c = c + 32;
return (c);
}

20
ft_toupper.c Normal file
View File

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_toupper.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/29 00:14:15 by apommier #+# #+# */
/* Updated: 2020/11/29 17:21:12 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
int ft_toupper(int c)
{
if (c >= 'a' && c <= 'z')
c = c - 32;
return (c);
}