bozosujet
This commit is contained in:
39
philo/utils/ft_atoi.c
Normal file
39
philo/utils/ft_atoi.c
Normal file
@ -0,0 +1,39 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atoi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/09/27 16:14:34 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/04/27 11:27:44 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "utils.h"
|
||||
#include <stddef.h>
|
||||
|
||||
int ft_atoi(const char *str)
|
||||
{
|
||||
int out;
|
||||
char sign;
|
||||
size_t i;
|
||||
|
||||
sign = 1;
|
||||
i = 0;
|
||||
while (str[i] == '-' || str[i] == '+')
|
||||
{
|
||||
if (str[i] == '-')
|
||||
sign = -1;
|
||||
if (str[i] == '+')
|
||||
sign = 1;
|
||||
i++;
|
||||
}
|
||||
out = 0;
|
||||
while (str[i] >= '0' && str[i] <= '9')
|
||||
{
|
||||
out = out * 10 + str[i] - 48;
|
||||
i++;
|
||||
}
|
||||
return (out * sign);
|
||||
}
|
34
philo/utils/ft_isnum.c
Normal file
34
philo/utils/ft_isnum.c
Normal file
@ -0,0 +1,34 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isnum.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/03/08 14:43:33 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/04/19 13:49:58 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../philo.h"
|
||||
#include <stddef.h>
|
||||
#include <limits.h>
|
||||
|
||||
bool ft_isnum(char str[])
|
||||
{
|
||||
size_t i;
|
||||
size_t num;
|
||||
|
||||
num = 0;
|
||||
i = 0;
|
||||
while (str[i] != '\0')
|
||||
{
|
||||
if (str[i] > '9' || str[i] < '0')
|
||||
return (0);
|
||||
num = num * 10 + str[i] - 48;
|
||||
if (num > INT_MAX)
|
||||
return (0);
|
||||
i++;
|
||||
}
|
||||
return (1);
|
||||
}
|
24
philo/utils/utils.h
Normal file
24
philo/utils/utils.h
Normal file
@ -0,0 +1,24 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* utils.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/11 14:38:07 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/04/25 14:09:53 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef UTILS_H
|
||||
# define UTILS_H
|
||||
# include <stddef.h>
|
||||
# include <stdbool.h>
|
||||
|
||||
bool ft_isnum(char str[]);
|
||||
int ft_atoi(const char str[]);
|
||||
void ft_putchar(char c);
|
||||
void ft_putstr(char str[]);
|
||||
void ft_putnum(size_t num, size_t padding);
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user