correction memcpy pour le cas ou dst et src sont nuls

This commit is contained in:
Hugo LAMY
2019-11-28 13:51:50 +01:00
parent feede2804f
commit b542d8adc0
152 changed files with 3206 additions and 5 deletions

55
srcs/ft_itoa.c Normal file
View File

@@ -0,0 +1,55 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_itoa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/25 13:59:01 by hulamy #+# #+# */
/* Updated: 2019/11/25 14:21:01 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** 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)
{
char *str;
int len;
long int nbis;
len = (n < 0) ? 2 : 1;
nbis = n;
while (nbis /= 10)
len++;
nbis = n;
nbis *= (nbis < 0) ? -1 : 1;
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';
if (n < 0)
str[0] = '-';
return (str);
}