Compare commits
2 Commits
603303a21b
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f86c2cf5cb | ||
|
|
2be81d5630 |
4
Makefile
4
Makefile
@@ -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 \
|
||||||
|
|||||||
@@ -11,11 +11,11 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef LIBFT_H
|
#ifndef LIBFT_H
|
||||||
# define LIBFT_H
|
#define LIBFT_H
|
||||||
# include <unistd.h> // for write
|
#include <unistd.h> // for write
|
||||||
# include <stdlib.h> // for malloc and free
|
#include <stdlib.h> // for malloc and free
|
||||||
# include "ft_gnl.h"
|
#include "ft_gnl.h"
|
||||||
# include "ft_printf.h"
|
#include "ft_printf.h"
|
||||||
|
|
||||||
void *ft_memset(void *b, int c, size_t len);
|
void *ft_memset(void *b, int c, size_t len);
|
||||||
void ft_bzero(void *s, size_t n);
|
void ft_bzero(void *s, size_t n);
|
||||||
@@ -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);
|
||||||
@@ -105,7 +94,7 @@ void ft_lstloop(t_list *lst, void (*f)(void *));
|
|||||||
void ft_lstloop_back(t_list *lst, void (*f)(void *));
|
void ft_lstloop_back(t_list *lst, void (*f)(void *));
|
||||||
t_list *ft_lstbegin(t_list *lst);
|
t_list *ft_lstbegin(t_list *lst);
|
||||||
t_list *ft_lstend(t_list *lst);
|
t_list *ft_lstend(t_list *lst);
|
||||||
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 *));
|
||||||
void ft_lstinsert(t_list *lst, t_list *new);
|
void ft_lstinsert(t_list *lst, t_list *new);
|
||||||
void ft_lsterase(t_list *lst, void (*del)(void *));
|
void ft_lsterase(t_list *lst, void (*del)(void *));
|
||||||
void ft_lstfree(t_list *lst, void (*del)(void *));
|
void ft_lstfree(t_list *lst, void (*del)(void *));
|
||||||
@@ -133,10 +122,10 @@ int ft_atoibase(char *str, char *base);
|
|||||||
char *ft_convertbase(char *nbr, char *base_from, char *base_to);
|
char *ft_convertbase(char *nbr, char *base_from, char *base_to);
|
||||||
char *ft_convertbase_free(char *nbr, char *b_from, char *b_to);
|
char *ft_convertbase_free(char *nbr, char *b_from, char *b_to);
|
||||||
char **ft_strmultisplit(char *str, char *charset);
|
char **ft_strmultisplit(char *str, char *charset);
|
||||||
int ft_any(char **tab, int (*f)(char*));
|
int ft_any(char **tab, int (*f)(char *));
|
||||||
void ft_foreach(int *tab, int length, void (*f)(int));
|
void ft_foreach(int *tab, int length, void (*f)(int));
|
||||||
int ft_issort(int *tab, int length, int (*f)(int, int));
|
int ft_issort(int *tab, int length, int (*f)(int, int));
|
||||||
int *ft_arraymap(int *tab, int length, int(*f)(int));
|
int *ft_arraymap(int *tab, int length, int (*f)(int));
|
||||||
void ft_putnbrendl(int n);
|
void ft_putnbrendl(int n);
|
||||||
void ft_putnbrendl_fd(int n, int fd);
|
void ft_putnbrendl_fd(int n, int fd);
|
||||||
char *ft_concat_free(char *str1, char *str2);
|
char *ft_concat_free(char *str1, char *str2);
|
||||||
@@ -147,6 +136,6 @@ int ft_sign(int i);
|
|||||||
int ft_sqrt(int i);
|
int ft_sqrt(int i);
|
||||||
void ft_free_tab(char **tab);
|
void ft_free_tab(char **tab);
|
||||||
|
|
||||||
int ft_arrint(int * intarr, int comp, size_t size);
|
int ft_arrint(int *intarr, int comp, size_t size);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
42
srcs/ft_atof.c
Normal file
42
srcs/ft_atof.c
Normal 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);
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
26
srcs/ft_isspace.c
Normal 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);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user