enleve strnew dans itoa
This commit is contained in:
@@ -6,11 +6,30 @@
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/14 21:10:25 by hulamy #+# #+# */
|
||||
/* Updated: 2018/11/14 21:36:38 by hulamy ### ########.fr */
|
||||
/* Updated: 2019/11/25 11:57:23 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
/*
|
||||
** take an integer and give a string
|
||||
*/
|
||||
|
||||
/*
|
||||
** #include <libc.h>
|
||||
**
|
||||
** char *ft_itoa(int n)
|
||||
**
|
||||
** int main(int ac, char **av)
|
||||
** {
|
||||
** if (ac == 2)
|
||||
** {
|
||||
** printf("%s\n",ft_itoa(atoi(av[1])));
|
||||
** }
|
||||
** return 0;
|
||||
** }
|
||||
**
|
||||
** #include "libft.h"
|
||||
*/
|
||||
|
||||
char *ft_itoa(int n)
|
||||
{
|
||||
@@ -24,8 +43,9 @@ char *ft_itoa(int n)
|
||||
len++;
|
||||
nbis = n;
|
||||
nbis *= (nbis < 0) ? -1 : 1;
|
||||
if (!(str = ft_strnew(len)))
|
||||
if (!(str = (char *)malloc(sizeof(char) * (len + 1))))
|
||||
return (NULL);
|
||||
str[len] = '\0';
|
||||
str[--len] = nbis % 10 + '0';
|
||||
while (nbis /= 10)
|
||||
str[--len] = nbis % 10 + '0';
|
||||
|
||||
Reference in New Issue
Block a user