-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Anaelle LECLABART
committed
Jan 2, 2019
1 parent
7e84cd4
commit 07401fb
Showing
4 changed files
with
76 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
# By: anaiel <[email protected]> +#+ +:+ +#+ # | ||
# +#+#+#+#+#+ +#+ # | ||
# Created: 2018/11/06 17:19:55 by anleclab #+# #+# # | ||
# Updated: 2019/01/02 10:38:38 by anleclab ### ########.fr # | ||
# Updated: 2019/01/02 11:56:54 by anleclab ### ########.fr # | ||
# # | ||
# **************************************************************************** # | ||
|
||
|
@@ -25,7 +25,7 @@ SRC = ft_memset.c ft_bzero.c ft_memcpy.c ft_memccpy.c ft_memmove.c ft_memchr.c \ | |
ft_lstdelone.c ft_lstdel.c ft_lstadd.c ft_lstiter.c ft_lstmap.c \ | ||
ft_strsplitlst.c ft_putstrarray.c ft_putstrlst.c ft_putfile.c \ | ||
ft_filelinecount.c ft_putwchar.c ft_printbits.c ft_wchar_to_bytes.c \ | ||
ft_double_power.c ft_array_swap.c | ||
ft_double_power.c ft_array_swap.c ft_itoa_base.c | ||
OBJ = $(SRC:.c=.o) | ||
|
||
.PHONY: all, clean, fclean, re | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: anaiel <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2018/11/06 17:19:32 by anleclab #+# #+# */ | ||
/* Updated: 2019/01/02 10:39:19 by anleclab ### ########.fr */ | ||
/* Updated: 2019/01/02 11:57:30 by anleclab ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -92,5 +92,6 @@ int ft_putwchar(wchar_t c); | |
unsigned char *ft_wchar_to_bytes(wint_t c); | ||
double ft_double_power(double n, int pow); | ||
void ft_array_swap(int *array, int i1, int i2); | ||
char *ft_itoa_base(int n, int base); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_itoa_base.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: anleclab <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2019/01/02 11:39:22 by anleclab #+# #+# */ | ||
/* Updated: 2019/01/02 11:55:06 by anleclab ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include <stdlib.h> | ||
#include "../libft.h" | ||
|
||
static char *init_base(int base) | ||
{ | ||
char *charbase; | ||
int i; | ||
|
||
if (base < 2 || base > 16) | ||
return (NULL); | ||
if (!(charbase = ft_strnew(base + 1))) | ||
return (NULL); | ||
i = 0; | ||
while (i < base && i < 10) | ||
charbase[i] = i; | ||
while (i < base) | ||
charbase[i] = i - 10 + 'A'; | ||
return (charbase); | ||
} | ||
|
||
static int nb_digits(unsigned int nb, int base) | ||
{ | ||
int nbdigits; | ||
|
||
nbdigits = 0; | ||
if (nb == 0) | ||
return (1); | ||
while (nb) | ||
{ | ||
nbdigits++; | ||
nb /= base; | ||
} | ||
return (nbdigits); | ||
} | ||
|
||
char *ft_itoa_base(int n, int base) | ||
{ | ||
char *charbase; | ||
char *res; | ||
unsigned int nb; | ||
int nbdigits; | ||
int i; | ||
|
||
if (!(charbase = init_base(base))) | ||
return (NULL); | ||
nb = (n < 0) ? -n : n; | ||
nbdigits = nb_digits(nb, base); | ||
if (!(res = ft_strnew(nbdigits + 1))) | ||
return (NULL); | ||
i = -1; | ||
while (++i < nbdigits - 1) | ||
{ | ||
res[nbdigits - 1 - i] = charbase[nb % base]; | ||
nb /= base; | ||
} | ||
free(charbase); | ||
return (res); | ||
} |