macros prefixed with FT_

This commit is contained in:
Jack Halford 2016-09-21 21:27:23 +02:00
parent c04af61063
commit 80b64fb832
5 changed files with 37 additions and 11 deletions

View file

@ -23,7 +23,7 @@ void ft_putnbr(int n)
} }
else if (n < 0) else if (n < 0)
ft_putchar('-'); ft_putchar('-');
n = ABS(n); n = FT_ABS(n);
if (n >= 10) if (n >= 10)
ft_putnbr(n / 10); ft_putnbr(n / 10);
ft_putchar(n % 10 + '0'); ft_putchar(n % 10 + '0');

View file

@ -23,7 +23,7 @@ void ft_putnbr_fd(int n, int fd)
} }
else if (n < 0) else if (n < 0)
ft_putchar_fd('-', fd); ft_putchar_fd('-', fd);
n = ABS(n); n = FT_ABS(n);
if (n >= 10) if (n >= 10)
ft_putnbr_fd(n / 10, fd); ft_putnbr_fd(n / 10, fd);
ft_putchar_fd(n % 10 + '0', fd); ft_putchar_fd(n % 10 + '0', fd);

21
libft/ft_strrev.c Normal file
View file

@ -0,0 +1,21 @@
#include "libft.h"
char *ft_strrev(char *str)
{
int len;
char tmp;
int i;
i = 0;
len = 0;
while (str[len] != '\0')
len++;
while (i < len / 2)
{
tmp = str[len - (i + 1)];
str[len - (i + 1)] = str[i];
str[i] = tmp;
i++;
}
return (str);
}

View file

@ -6,10 +6,10 @@ char *ft_strtrim(char const *s)
size_t size; size_t size;
out = ft_strdup(s); out = ft_strdup(s);
while (*out && SEP(*out)) while (*out && FT_SEP(*out))
out++; out++;
size = ft_strlen(out); size = ft_strlen(out);
while (size - 1 && SEP(out[size - 1])) while (size - 1 && FT_SEP(out[size - 1]))
{ {
size--; size--;
out[size] = '\0'; out[size] = '\0';

View file

@ -4,13 +4,13 @@
# include <unistd.h> # include <unistd.h>
# include <stdio.h> # include <stdio.h>
# include <stdlib.h> # include <stdlib.h>
# define SEP(x) (x == ' ' || x == '\t' || x == '\n') # define FT_SEP(x) (x == ' ' || x == '\t' || x == '\n')
# define ABS(x) (((x) < 0) ? -(x) : (x)) # define FT_ABS(x) (((x) < 0) ? -(x) : (x))
# define NEG(x) (((x) < 0) ? 1 : 0) # define FT_NEG(x) (((x) < 0) ? 1 : 0)
# define POS(x) (((x) > 0) ? 1 : 0) # define FT_POS(x) (((x) > 0) ? 1 : 0)
# define MIN(a, b) ((a) < (b) ? (a) : (b)) # define FT_MIN(a, b) ((a) < (b) ? (a) : (b))
# define MAX(a, b) ((a) > (b) ? (a) : (b)) # define FT_MAX(a, b) ((a) > (b) ? (a) : (b))
# define DIST(a, b) (ABS((a) - (b))) # define FT_DIST(a, b) (ABS((a) - (b)))
typedef struct s_list typedef struct s_list
{ {
@ -99,5 +99,10 @@ t_list *ft_lst_find(t_list *begin_list, void *data_ref, int (*cmp)());
t_list *ft_lstpop(t_list **lst); t_list *ft_lstpop(t_list **lst);
int ft_diff(void *a, void *b); int ft_diff(void *a, void *b);
char *ft_strrev(char *str);
t_list *ft_id(t_list *a); t_list *ft_id(t_list *a);
char *ft_itoa_base(int nbr, char *base, char *flags);
char *ft_lltoa_base(long long nbr, char *base, char *flags);
char *ft_ulltoa_base(unsigned long long nbr, char *base);
char *ft_uitoa_base(unsigned int nbr, char *base);
#endif #endif