piscine-rush00-ultra/ex00/ft_lib.c

84 lines
1.7 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lib.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/18 22:33:38 by tischmid #+# #+# */
/* Updated: 2023/03/19 03:31:09 by tischmid ### ########.fr */
/* */
/* ************************************************************************** */
#include "include/ft_putchar.h"
void ft_putstr(char *str)
{
int i;
i = 0;
while (str[i] != '\0')
ft_putchar(str[i++]);
}
void ft_putnbr(int nb)
{
char last_digit;
if (nb < 0)
{
ft_putchar('-');
if (nb == 1 << 31)
{
nb += 2e9;
ft_putchar('2');
}
nb *= -1;
}
last_digit = nb % 10 + '0';
if (nb > 9)
{
nb /= 10;
ft_putnbr(nb);
}
ft_putchar(last_digit);
}
int ft_atoi(char *str)
{
int i;
int number;
i = 0;
number = 0;
while (str[i] >= '0' && str[i] <= '9')
number = number * 10 + (str[i++] - '0');
return (number);
}
char *ft_strcpy(char *s1, char *s2)
{
int i;
i = -1;
while (s2[++i] != '\0')
s1[i] = s2[i];
s1[i] = '\0';
return (s1);
}
char *ft_strcat(char *s1, char *s2)
{
int i;
int j;
i = 0;
while (s1[i] != '\0')
++i;
j = -1;
while (s2[++j] != '\0')
s1[i++] = s2[j];
s1[i] = '\0';
return (s1);
}