feat(convert/atou): adding the atou function
- Can be usefull when the parsing of some project (like philosophers)
This commit is contained in:
parent
4e15449d12
commit
28be9d6b91
2 changed files with 51 additions and 1 deletions
40
convert/ft_atou.c
Normal file
40
convert/ft_atou.c
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_atou.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/11/08 17:22:41 by rparodi #+# #+# */
|
||||||
|
/* Updated: 2025/09/08 10:16:01 by rparodi ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
static int ft_check_space(int c)
|
||||||
|
{
|
||||||
|
if (c == 32 || (c >= 9 && c <= 13))
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t ft_atou(const char *nptr)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
size_t number;
|
||||||
|
|
||||||
|
if (!nptr)
|
||||||
|
return (0);
|
||||||
|
i = 0;
|
||||||
|
number = 0;
|
||||||
|
while (nptr[i])
|
||||||
|
{
|
||||||
|
if (nptr[i] >= '0' && nptr[i] <= '9')
|
||||||
|
number = (number * 10) + nptr[i] - '0';
|
||||||
|
else
|
||||||
|
break ;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (number);
|
||||||
|
}
|
||||||
|
|
@ -6,13 +6,15 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/10/31 14:57:24 by rparodi #+# #+# */
|
/* Created: 2024/10/31 14:57:24 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/09/05 16:07:54 by rparodi ### ########.fr */
|
/* Updated: 2025/09/08 10:17:01 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef CONVERT_H
|
#ifndef CONVERT_H
|
||||||
# define CONVERT_H
|
# define CONVERT_H
|
||||||
|
|
||||||
|
# include <stddef.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Converts integer to string
|
* @brief Converts integer to string
|
||||||
*
|
*
|
||||||
|
|
@ -29,6 +31,14 @@ char *ft_itoa(int n);
|
||||||
*/
|
*/
|
||||||
int ft_atoi(const char *nptr);
|
int ft_atoi(const char *nptr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Converts string to size_t
|
||||||
|
*
|
||||||
|
* @param nptr the string that will be converted
|
||||||
|
* @return The unsigned long long on the string
|
||||||
|
*/
|
||||||
|
size_t ft_atou(const char *nptr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Converts string to long long integer
|
* @brief Converts string to long long integer
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue