Skip to content

Instantly share code, notes, and snippets.

@qleguennec
Created December 8, 2015 22:30
Show Gist options
  • Save qleguennec/33b0064ac20d532c1cf5 to your computer and use it in GitHub Desktop.
Save qleguennec/33b0064ac20d532c1cf5 to your computer and use it in GitHub Desktop.
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_itoa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qle-guen <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/26 14:48:09 by qle-guen #+# #+# */
/* Updated: 2015/12/08 23:30:25 by qle-guen ### ########.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
char *ft_itoa(int n)
{
char s[1024];
int i;
int neg;
i = 0;
neg = 0;
if (n == 0)
s[i++] = '0';
if (n < 0)
{
n = n * (-1);
neg = 1;
}
while (n != 0)
{
s[i++] = (n % 10) + 48;
n /= 10;
}
if (neg)
s[i++] = '-';
s[i] = '\0';
return (ft_strrev(s));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment