Compare commits

..

2 Commits

Author SHA1 Message Date
hugogogo
f86c2cf5cb add ft_atof 2026-04-29 00:52:48 +02:00
hugogogo
2be81d5630 adding ft_isspace 2026-04-28 19:32:48 +02:00
6 changed files with 210 additions and 137 deletions

View File

@@ -30,6 +30,7 @@ SRCS = ft_memset.c \
ft_isalnum.c \ ft_isalnum.c \
ft_isnumber.c \ ft_isnumber.c \
ft_isascii.c \ ft_isascii.c \
ft_isspace.c \
ft_isprint.c \ ft_isprint.c \
ft_toupper.c \ ft_toupper.c \
ft_tolower.c \ ft_tolower.c \
@@ -66,8 +67,10 @@ SRCS = ft_memset.c \
\ \
ft_atoi.c \ ft_atoi.c \
ft_atol.c \ ft_atol.c \
ft_atof.c \
ft_itoa.c \ ft_itoa.c \
ft_utoa.c \ ft_utoa.c \
ft_atoibase.c \
\ \
ft_putchar.c \ ft_putchar.c \
ft_putstr.c \ ft_putstr.c \
@@ -93,7 +96,6 @@ SRCS = ft_memset.c \
ft_lstcopy.c \ ft_lstcopy.c \
\ \
ft_any.c \ ft_any.c \
ft_atoibase.c \
ft_convertbase.c \ ft_convertbase.c \
ft_convertbase_free.c \ ft_convertbase_free.c \
ft_foreach.c \ ft_foreach.c \

View File

@@ -30,6 +30,7 @@ int ft_isdigit(int c);
int ft_isnumber(char *nb); int ft_isnumber(char *nb);
int ft_isalnum(int c); int ft_isalnum(int c);
int ft_isascii(int c); int ft_isascii(int c);
int ft_isspace(int c);
int ft_isprint(int c); int ft_isprint(int c);
int ft_toupper(int c); int ft_toupper(int c);
int ft_tolower(int c); int ft_tolower(int c);
@@ -42,6 +43,7 @@ size_t ft_strlcat(char *dst, const char *src, size_t size);
char *ft_strnstr(const char *b, const char *l, size_t s); char *ft_strnstr(const char *b, const char *l, size_t s);
int ft_atoi(const char *str); int ft_atoi(const char *str);
long ft_atol(const char *str); long ft_atol(const char *str);
double ft_atof(const char *str);
void *ft_calloc(size_t count, size_t size); void *ft_calloc(size_t count, size_t size);
char *ft_strdup(const char *s1); char *ft_strdup(const char *s1);
@@ -62,21 +64,8 @@ void ft_putstr_fd(const char *s, int fd);
void ft_putnbr_fd(int n, int fd); void ft_putnbr_fd(int n, int fd);
void ft_putnbrbase_fd(int nbr, const char *base, int fd); void ft_putnbrbase_fd(int nbr, const char *base, int fd);
/* // void ft_putendl(char const *str);
void ft_putchar(char c); // void ft_putendl_fd(char *s, int fd);
void ft_putstr(char *s);
void ft_putnbr(int n);
void ft_putnbrbase(int nbr, char *base);
void ft_putchar_fd(char c, int fd);
void ft_putstr_fd(char *s, int fd);
void ft_putnbr_fd(int n, int fd);
void ft_putnbrbase_fd(int nbr, char *base, int fd);
*/
/*
void ft_putendl(char const *str);
void ft_putendl_fd(char *s, int fd);
*/
typedef struct s_list typedef struct s_list
{ {
@@ -85,19 +74,19 @@ typedef struct s_list
struct s_list *next; struct s_list *next;
} t_list; } t_list;
/* // t_list *ft_lstnew(void *content);
t_list *ft_lstnew(void *content); // void ft_lstadd_front(t_list **alst, t_list *n);
void ft_lstadd_front(t_list **alst, t_list *n); // void *ft_lstadd_back(t_list **alst, t_list *n);
void *ft_lstadd_back(t_list **alst, t_list *n); // int ft_lstsize(t_list *lst);
int ft_lstsize(t_list *lst); // t_list *ft_lstlast(t_list *lst);
t_list *ft_lstlast(t_list *lst); // void ft_lstdelone(t_list *lst, void (*del)(void *));
void ft_lstdelone(t_list *lst, void (*del)(void *)); // void ft_lstclear(t_list **lst, void (*del)(void *));
void ft_lstclear(t_list **lst, void (*del)(void *)); // void ft_lstiter(t_list *lst, void (*f)(void *));
void ft_lstiter(t_list *lst, void (*f)(void *)); // t_list *ft_lstmap(t_list *l, void *(*f)(void *), void (*d)(void *));
t_list *ft_lstmap(t_list *l, void *(*f)(void*), void (*d)(void*));
*/
// void ft_lstremove(t_list *lst, void (*del)(void *)); // void ft_lstremove(t_list *lst, void (*del)(void *));
// t_list *ft_lstfind(t_list *lst, void *to_find, int (*comp)(void *, void *)); // t_list *ft_lstfind(t_list *lst, void *to_find, int (*comp)(void *, void *));
t_list *ft_lstcreate(void *content); t_list *ft_lstcreate(void *content);
void *ft_lstpush_back(t_list **lst, t_list *new); void *ft_lstpush_back(t_list **lst, t_list *new);
void ft_lstpush_front(t_list **alst, t_list *new); void ft_lstpush_front(t_list **alst, t_list *new);

42
srcs/ft_atof.c Normal file
View File

@@ -0,0 +1,42 @@
#include <stdio.h>
#include "libft.h"
double ft_atof(const char *str)
{
double nbr;
int i;
int negatif;
double fraction;
i = 0;
negatif = 1;
nbr = 0.0;
fraction = 1.0;
// Skip leading whitespace
while ((str[i] == ' ') || (str[i] > 8 && str[i] < 14))
i++;
// Handle optional sign
if (str[i] == '-')
negatif = -1;
if (str[i] == '+' || str[i] == '-')
i++;
// Parse integer part
while (str[i] >= '0' && str[i] <= '9')
nbr = nbr * 10.0 + (str[i++] - '0');
// Parse fractional part if '.' is present
if (str[i] == '.')
{
i++;
while (str[i] >= '0' && str[i] <= '9')
{
fraction /= 10.0;
nbr += (str[i++] - '0') * fraction;
}
}
return (nbr * negatif);
}

View File

@@ -21,13 +21,20 @@ int ft_atoi(const char *str)
i = 0; i = 0;
negatif = 1; negatif = 1;
nbr = 0; nbr = 0;
// Skip leading whitespace
while ((str[i] == ' ') || (str[i] > 8 && str[i] < 14)) while ((str[i] == ' ') || (str[i] > 8 && str[i] < 14))
i++; i++;
// Handle optional sign
if (str[i] == '-') if (str[i] == '-')
negatif = -1; negatif = -1;
if (str[i] == '+' || str[i] == '-') if (str[i] == '+' || str[i] == '-')
i++; i++;
// parse integer
while (str[i] >= '0' && str[i] <= '9') while (str[i] >= '0' && str[i] <= '9')
nbr = nbr * 10 + (str[i++] - '0'); nbr = nbr * 10 + (str[i++] - '0');
return (nbr * negatif); return (nbr * negatif);
} }

View File

@@ -10,13 +10,20 @@ long ft_atol(const char *str)
i = 0; i = 0;
negatif = 1; negatif = 1;
nbr = 0; nbr = 0;
// Skip leading whitespace
while ((str[i] == ' ') || (str[i] > 8 && str[i] < 14)) while ((str[i] == ' ') || (str[i] > 8 && str[i] < 14))
i++; i++;
// Handle optional sign
if (str[i] == '-') if (str[i] == '-')
negatif = -1; negatif = -1;
if (str[i] == '+' || str[i] == '-') if (str[i] == '+' || str[i] == '-')
i++; i++;
// parse integer
while (str[i] >= '0' && str[i] <= '9') while (str[i] >= '0' && str[i] <= '9')
nbr = nbr * 10 + (str[i++] - '0'); nbr = nbr * 10 + (str[i++] - '0');
return (nbr * negatif); return (nbr * negatif);
} }

26
srcs/ft_isspace.c Normal file
View File

@@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalpha.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/25 13:55:15 by hulamy #+# #+# */
/* Updated: 2019/11/25 13:55:17 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#define SPACE ' '
#define FORM_FEED '\f'
#define NEWLINE '\n'
#define CARRIAGE_RETURN '\r'
#define HORIZONTAL_TAB '\t'
#define VERTICAL_TAB '\v'
int ft_isspace(int c)
{
return (c == SPACE || c == FORM_FEED || c == NEWLINE ||
c == CARRIAGE_RETURN || c == HORIZONTAL_TAB || c == VERTICAL_TAB);
}