sync
This commit is contained in:
24
Rush_02/rush-02/ex00/ft/ft.h
Normal file
24
Rush_02/rush-02/ex00/ft/ft.h
Normal file
@@ -0,0 +1,24 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/21 14:02:24 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/21 16:36:21 by gbaconni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef FT_H
|
||||
# define FT_H
|
||||
|
||||
int ft_strlen(char *str);
|
||||
int ft_strcmp(char *s1, char *s2);
|
||||
int ft_atoi(char *str);
|
||||
void ft_putnbr(int nb);
|
||||
void ft_putstr(char *str);
|
||||
void ft_putchar(char c);
|
||||
char *ft_strcat(char *dest, char *src);
|
||||
|
||||
#endif
|
||||
38
Rush_02/rush-02/ex00/ft/ft_atoi.c
Normal file
38
Rush_02/rush-02/ex00/ft/ft_atoi.c
Normal file
@@ -0,0 +1,38 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atoi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/21 14:02:34 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/21 16:15:10 by gbaconni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_atoi(char *str)
|
||||
{
|
||||
int nb;
|
||||
int s;
|
||||
int i;
|
||||
|
||||
nb = 0;
|
||||
s = 1;
|
||||
i = 0;
|
||||
while (str[i] != '\0' && \
|
||||
(str[i] == ' ' || (str[i] >= '\t' && str[i] <= '\r')))
|
||||
i++;
|
||||
while (str[i] != '\0')
|
||||
{
|
||||
if (str[i] == '+')
|
||||
s += 0;
|
||||
else if (str[i] == '-')
|
||||
s *= -1;
|
||||
else if (str[i] >= '0' && str[i] <= '9')
|
||||
nb = nb * 10 + str[i] - '0';
|
||||
else
|
||||
break ;
|
||||
i++;
|
||||
}
|
||||
return (nb * s);
|
||||
}
|
||||
18
Rush_02/rush-02/ex00/ft/ft_putchar.c
Normal file
18
Rush_02/rush-02/ex00/ft/ft_putchar.c
Normal file
@@ -0,0 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putchar.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/21 15:27:46 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/21 15:27:47 by gbaconni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
void ft_putchar(char c)
|
||||
{
|
||||
write(1, &c, 1);
|
||||
}
|
||||
39
Rush_02/rush-02/ex00/ft/ft_putnbr.c
Normal file
39
Rush_02/rush-02/ex00/ft/ft_putnbr.c
Normal file
@@ -0,0 +1,39 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putnbr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/21 15:32:13 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/21 18:10:53 by gbaconni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
void ft_putnbr(int nb)
|
||||
{
|
||||
char c;
|
||||
|
||||
if (nb < 0)
|
||||
{
|
||||
nb *= -1;
|
||||
write(1, "-", 1);
|
||||
}
|
||||
if (nb >= 0 && nb <= 9)
|
||||
{
|
||||
c = nb + '0';
|
||||
write(1, &c, 1);
|
||||
}
|
||||
else if (nb == -2147483648)
|
||||
{
|
||||
ft_putnbr((nb / 10) * -1);
|
||||
ft_putnbr((nb % 10) * -1);
|
||||
}
|
||||
else
|
||||
{
|
||||
ft_putnbr(nb / 10);
|
||||
ft_putnbr(nb % 10);
|
||||
}
|
||||
}
|
||||
22
Rush_02/rush-02/ex00/ft/ft_putstr.c
Normal file
22
Rush_02/rush-02/ex00/ft/ft_putstr.c
Normal file
@@ -0,0 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/21 14:02:45 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/21 14:02:48 by gbaconni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
void ft_putstr(char *str)
|
||||
{
|
||||
char *p_str;
|
||||
|
||||
p_str = str;
|
||||
while (*p_str != '\0')
|
||||
write(1, p_str++, 1);
|
||||
}
|
||||
26
Rush_02/rush-02/ex00/ft/ft_strcat.c
Normal file
26
Rush_02/rush-02/ex00/ft/ft_strcat.c
Normal file
@@ -0,0 +1,26 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strcat.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/21 14:02:59 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/21 14:03:01 by gbaconni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
char *ft_strcat(char *dest, char *src)
|
||||
{
|
||||
char *s1;
|
||||
char *s2;
|
||||
|
||||
s1 = dest;
|
||||
s2 = src;
|
||||
while (*s1 != '\0')
|
||||
s1++;
|
||||
while (*s2 != '\0')
|
||||
*s1++ = *s2++;
|
||||
*s1 = '\0';
|
||||
return (dest);
|
||||
}
|
||||
28
Rush_02/rush-02/ex00/ft/ft_strcmp.c
Normal file
28
Rush_02/rush-02/ex00/ft/ft_strcmp.c
Normal file
@@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strcmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/21 14:04:11 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/21 14:04:12 by gbaconni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_strcmp(char *s1, char *s2)
|
||||
{
|
||||
char c1;
|
||||
char c2;
|
||||
|
||||
c1 = '\0';
|
||||
c2 = '\0';
|
||||
while (c1 == c2)
|
||||
{
|
||||
c1 = *s1++;
|
||||
c2 = *s2++;
|
||||
if (c1 == '\0')
|
||||
break ;
|
||||
}
|
||||
return (c1 - c2);
|
||||
}
|
||||
23
Rush_02/rush-02/ex00/ft/ft_strlen.c
Normal file
23
Rush_02/rush-02/ex00/ft/ft_strlen.c
Normal file
@@ -0,0 +1,23 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlen.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/21 14:04:24 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/21 14:04:25 by gbaconni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_strlen(char *str)
|
||||
{
|
||||
int size;
|
||||
|
||||
size = 0;
|
||||
while (str[size] != '\0')
|
||||
{
|
||||
size++;
|
||||
}
|
||||
return (size);
|
||||
}
|
||||
Reference in New Issue
Block a user