Ejemplo n.º 1
0
char		*ft_ltoa_base(long long n, int base)
{
	char *number;
	char tmp[66];

	ft_bzero(tmp, 66);
	if (n < 0)
		number = ft_strjoin("-", ft_strrev(ft_lbn(n, tmp, -1, base)));
	else
		number = ft_strdup(ft_strrev(ft_lbp(n, tmp, -1, base)));
	return (number);
}
Ejemplo n.º 2
0
char	*pf_itoa(long long n, int absoluter)
{
	long	j;
	char	*res;

	if (n == 0)
		return (ft_strdup("0"));
	if (n == LONG_MAX)
		return (ft_strdup("9223372036854775807"));
	if (n == LONG_MIN)
	{
		if (absoluter)
			return (ft_strdup("9223372036854775808"));
		return (ft_strdup("-9223372036854775808"));
	}
	j = n;
	if (j < 0)
		j *= -1;
	res = ft_memalloc(1);
	while (j)
	{
		res = ft_charjoin_f(&res, j % 10 + 48);
		j = j / 10;
	}
	if (n < 0 && !absoluter)
		res = ft_charjoin_f(&res, '-');
	return (ft_strrev(res));
}
Ejemplo n.º 3
0
int			main(int argc, char **argv)
{
	int			nbr_tetris;
	char		**grid;
	t_tetrimino	*tetris;
	t_coord		co;
	t_path		path;

	path.square_size = -1;
	path.path = ft_strnew(27);
	co.x = 0;
	co.y = 0;
	nbr_tetris = -1;
	if (argc != 2 || !(is_valid_file(argv[1])))
		write(1, "error\n", 6);
	else if (!(nbr_tetris = process_file(argv[1], 0, &tetris)))
		write(1, "error\n", 6);
	else
	{
		grid = create_grid(nbr_tetris);
		path = fill_grid(grid, tetris, co, nbr_tetris);
		ft_strrev(path.path);
		grid_from_str(path.path, grid, tetris, co);
		display_grid(grid);
		free_grid(grid);
	}
	return (0);
}
Ejemplo n.º 4
0
char		*ft_printf_i(void *n)
{
	int			sign;
	char		*buff;
	long int	len;
	long int	i;
	long int	nb;

	nb = (long int)(int)(long int)n;
	sign = (nb < 0 ? 'n' : 'p');
	nb = (nb < 0 ? -nb : nb);
	len = ft_nbrlen(nb);
	buff = (sign == 'n' ? ft_strnew(len + 1) : ft_strnew(len));
	if (buff == NULL)
		return (NULL);
	i = 0;
	while (i < len)
	{
		buff[i] = nb % 10 + '0';
		nb = nb / 10;
		i++;
	}
	buff[i] = (sign == 'n' ? '-' : 0);
	ft_strrev(buff);
	return (buff);
}
Ejemplo n.º 5
0
char			*ft_itoa_base(int value, int base)
{
	char	*str;
	int		i;
	int		isneg;

	if (base < 2 || base > 16 || value == 0)
		return (ft_returnzero());
	if (!(str = ft_allocstr(value, base)))
		return (NULL);
	i = 0;
	isneg = 0;
	if (base == 10 && value < 0)
		isneg = 1;
	while (value != 0)
	{
		if (value % base <= 9)
			str[i++] = ft_abs(value % base) + '0';
		else
			str[i++] = (ft_abs(value % base) - 10) + 'a';
		value /= base;
	}
	if (isneg)
		str[i++] = '-';
	str[i] = '\0';
	ft_strrev(str);
	return (str);
}
Ejemplo n.º 6
0
char	*ft_ltoa_base(long long n, long long base)
{
	char	*str;
	char	*ret;
	int		x;

	x = 0;
	if (!(str = (char *)ft_memalloc(sizeof(char) * 100)))
		return (NULL);
	while (n / base)
	{
		if (base > 10 && ft_abs(n % base) > 9)
			str[x] = ft_abs(n % base) - 10 + 'a';
		else
			str[x] = ft_abs(n % base) + '0';
		n = n / base;
		x++;
	}
	if (base > 10 && ft_abs(n % base) > 9)
		str[x] = ft_abs(n % base) - 10 + 'a';
	else
		str[x] = ft_abs(n % base) + '0';
	if (n < 0 && base == 10)
		str[++x] = '-';
	ret = ft_strndup(str, x + 2);
	free(str);
	return (ft_strrev(ret));
}
Ejemplo n.º 7
0
char	*ft_itoa(int n)
{
	char			*ret;
	int				i;
	unsigned int	res;

	i = 0;
	res = (n < 0) ? (n * -1) : n;
	ret = (char *)malloc(20 * sizeof(*ret));
	if (ret == NULL)
		return (NULL);
	while (res / 10 != 0)
	{
		ret[i] = (res % 10) + '0';
		res = (res / 10);
		i++;
	}
	if (n < 0)
	{
		ret[i + 1] = '-';
		ret[i + 2] = '\0';
	}
	if (n >= 0)
		ret[i + 1] = 0;
	ret[i] = res + '0';
	ret = ft_strrev(ret);
	return (ret);
}
Ejemplo n.º 8
0
Archivo: ft_itoa.c Proyecto: ggila/42
char		*ft_itoa(int n)
{
	char	*dst;
	int		sgn;
	int		str_len;
	int		i;

	sgn = (n < 0) ? -1 : 1;
	str_len = get_size(n) - ((sgn - 1) / 2);
	if (!(dst = ft_strnew(str_len)))
		return (NULL);
	dst[str_len] = '\0';
	if (n == 0)
		*dst = '0';
	i = 0;
	while (n != 0)
	{
		dst[i] = '0' + sgn * (n % 10);
		n = n / 10;
		i++;
	}
	if (sgn < 0)
		dst[i] = '-';
	ft_strrev(dst, str_len);
	return (dst);
}
Ejemplo n.º 9
0
static char				*calc(int n, int i, char *chain)
{
	int				isneg;
	unsigned int	nb;

	isneg = ft_isneg(n);
	if (isneg == 1)
		nb = n * -1;
	else
		nb = n;
	while (nb > 0)
	{
		chain[i] = ((nb % 10 + 48));
		nb = nb / 10;
		i++;
	}
	if (isneg == 1)
	{
		chain[i] = '-';
		i++;
	}
	chain[i] = '\0';
	ft_strrev(chain);
	return (chain);
}
Ejemplo n.º 10
0
char			*ft_itoa_base(int value, int base)
{
	int		sign;
	int		count;
	char	*str;

	count = 0;
	sign = is_negative(&value);
	if (base < 2 || base > 16)
		return ("");
	if (value == 0 || value == -0)
		return ("0");
	if (value == -2147483648)
		return ("-2147483648");
	if (value == 2147483647)
		return ("2147483647");
	if ((str = ft_strnew(ft_getlen(value, base) + sign))
			== NULL)
		return (NULL);
	count = ft_getstr(value, base, str);
	if (sign < 0 && base == 10)
		str[count++] = '-';
	str[count] = '\0';
	ft_strrev(str);
	return (str);
}
Ejemplo n.º 11
0
char				*ft_itoa(int n)
{
	int				i;
	unsigned int	x;
	char			*buff;
	int				neg;

	if (!(buff = ft_strnew(ft_nbrlen(n))))
		return (NULL);
	x = n;
	if ((neg = n) < 0)
		x = -n;
	i = 0;
	if (x == 0)
		buff[i++] = '0';
	while (x > 0)
	{
		buff[i++] = x % 10 + '0';
		x /= 10;
	}
	if (neg < 0)
		buff[i++] = '-';
	buff[i] = '\0';
	ft_strrev(buff);
	return (buff);
}
Ejemplo n.º 12
0
char			*ft_itoa(int nbr)
{
	int		pos;
	size_t	i;
	char	*str_number;

	if (!(str_size(&str_number, &pos, &i)))
		return (NULL);
	if (nbr == 0 || nbr == -2147483648)
		return (ft_zero_or_min(nbr));
	if (nbr < 0)
	{
		nbr = -nbr;
		pos = 0;
	}
	while (nbr)
	{
		str_number[i] = (nbr) % 10 + '0';
		nbr = nbr / 10;
		i++;
	}
	if (!pos)
		str_number[i++] = '-';
	str_number[i] = '\0';
	return (ft_strrev(str_number));
}
Ejemplo n.º 13
0
char		*ft_itox(long int n)
{
	char	*val;
	int		i;
	int		neg;

	neg = 0;
	i = 0;
	val = (char *)malloc(sizeof(long int) + 1);
	if (n < 0)
	{
		n = n * -1;
		neg = 1;
	}
	while (n > 16)
	{
		val[i] = ft_tohex(n % 16, -32);
		n = n / 16;
		i++;
	}
	val[i] = ft_tohex(n, -32);
	i++;
	if (neg == 1)
		val[i++] = '-';
	val[i] = '\0';
	return (ft_strrev(val));
}
Ejemplo n.º 14
0
char		*ft_itoa(int n)
{
	char	*res;
	char	*save;
	int		neg;

	if ((res = (char *)malloc(sizeof(char) * 13)) == NULL)
		return (NULL);
	neg = 0;
	save = res;
	if (n == 0)
		return (ft_strdup("0"));
	if (n == -2147483648)
		return (ft_strdup("-2147483648"));
	if (n < 0 && (n = -n))
		neg = -1;
	while (n > 0)
	{
		*res++ = ((n % 10) + '0');
		n = n / 10;
	}
	if (neg)
		*res++ = '-';
	*res = '\0';
	res = ft_strrev(save);
	return (res);
}
Ejemplo n.º 15
0
Archivo: ft_itoa.c Proyecto: TPelago/42
char		*ft_itoa(int number)
{
	int		number2;
	int		negative;
	size_t	size_str;
	char	*str_number;

	size_str = 0;
	negative = 0;
	if (number == 0 || number == -2147483648)
		return (ft_exception(number));
	if (number < 0 && ++negative)
		number = -number;
	number2 = number;
	while (number)
	{
		number = number / 10;
		size_str++;
	}
	str_number = malloc(sizeof(char) * (size_str + 1));
	if (!str_number)
		return (0);
	ft_itoa2(number2, &str_number, negative, 0);
	return (ft_strrev(str_number));
}
Ejemplo n.º 16
0
int main(void)
{
	char c[] = "Suhh dudes";
	ft_strrev(c);
	printf("Reverse String: %s\n", c);
	return (0);
}
Ejemplo n.º 17
0
int		main(void)
{
	char text[] = "Salut";

	printf("%s", ft_strrev(text));
	return (0);
}
Ejemplo n.º 18
0
int				exe_command(t_var *var, t_token *tk)
{
	pid_t		father;
	char		*path;
	char		**com;
	int			status;

	com = (tk->exe ? tk->exe : NULL);
	status = exec_bin(com, var);
	if (com && status == -1 && (path = get_path(com[0], var->tenv)))
	{
		ft_strrev(com[0]);
		check_for_back_quote(var, com);
		father = fork();
		if (!father)
		{
			sig_catcher_fork();
			exit(execve(path, com, var->tenv));
		}
		if (father > 0)
		{
			waitpid(father, &status, 0);
			status = WEXITSTATUS(status);
		}
		ft_strdel(&path);
	}
	return (status);
}
Ejemplo n.º 19
0
char			*ft_itoa(long n)
{
	char	*a_nb;
	int		neg;
	int		i;

	neg = 1;
	if (!(a_nb = malloc((ft_nbdigits(n) + 1) * sizeof(char))))
		return (NULL);
	if (n == 0 || n < -9223372036854775807)
		return (ft_except(n, &a_nb));
	if (n < 0)
	{
		neg = -1;
		n *= -1;
	}
	i = 0;
	while (n > 0)
	{
		a_nb[i++] = '0' + (n % 10);
		n /= 10;
	}
	if (neg == -1)
		a_nb[i++] = '-';
	a_nb[i] = '\0';
	return (ft_strrev(a_nb));
}
Ejemplo n.º 20
0
char			*ft_base16(uintmax_t n)
{
	uintmax_t			div;
	int					mod;
	char				*convert;
	int					i;

	i = 0;
	convert = ft_strnew(11);
	if (n == 0)
	{
		convert[0] = '0';
		return (convert);
	}
	div = n;
	while (div != 0)
	{
		div = n / 16;
		mod = n % 16;
		n = div;
		if (mod > 9)
			convert[i++] = mod + 55;
		else
			convert[i++] = mod + 48;
	}
	convert = ft_strrev(convert);
	return (convert);
}
Ejemplo n.º 21
0
char		*ft_itoc(long int n)
{
	char	*val;
	int		i;
	int		neg;

	neg = 0;
	i = 0;
	val = (char *)malloc(sizeof(long int) + 1);
	if (n < 0)
	{
		n = n * -1;
		neg = 1;
	}
	while (n > 8)
	{
		val[i] = (n % 8) + '0';
		n = n / 8;
		i++;
	}
	val[i] = n + '0';
	i++;
	if (neg == 1)
		val[i++] = '-';
	val[i] = '\0';
	return (ft_strrev(val));
}
Ejemplo n.º 22
0
char	*ft_itoa(int nbr)
{
	int		sign;
	int		length;
	char	*result;
	int		i;

	length = 0;
	if ((sign = nbr) < 0)
		nbr = -nbr;
	while (ft_power(10, length) <= nbr)
		length++;
	result = (char*)malloc(sizeof(int) * length);
	result[0] = (nbr % 10) + 48;
	i = 1;
	while ((nbr /= 10) > 0)
	{
		result[i] = (nbr % 10) + 48;
		i++;
	}
	if (sign < 0)
		result[i++] = '-';
	result[i] = '\0';
	return (ft_strrev(result));
}
Ejemplo n.º 23
0
char			*ft_itoa_base(long long int nbr, int base, char c)
{
	int		d[2];
	size_t	i;
	char	*str_number;

	if (!(str_size(&str_number, &d[1], &i, &d[0])))
		return (NULL);
	if (nbr == 0 || nbr == LLONG_MIN)
		return (ft_zero_or_min(nbr));
	if (nbr < 0)
	{
		nbr = -nbr;
		d[1] = 0;
	}
	while (nbr)
	{
		d[0] = nbr % base;
		str_number[i++] = (d[0] > 9) ? (d[0] - 10) + c : d[0] + '0';
		nbr = nbr / base;
	}
	if (!d[1])
		str_number[i++] = '-';
	str_number[i] = '\0';
	return (ft_strrev(str_number));
}
Ejemplo n.º 24
0
char		*ft_itoa(int n)
{
	char	*str;
	int 	sign;
	int 	i;

	i = 0;
	sign = 1;
	str = (char*)malloc(sizeof(*str) * 15);
	if (n == 0)
	{
		str[0] = '0';
		str[1] = '\0';
		return (str);
	}
	if (n < 0)
	{
		n = n + 1;
		n = -n;
	}
	else
		sign = 0;
	ft_itoa_cut(&i, &n, &sign, str);
	str[i] = '\0';
	ft_strrev(str);
	return (str);
}
Ejemplo n.º 25
0
int		main()
{
	char *test;

	test = "heyoo";
	printf("%s", ft_strrev("Hello"));
	return (0);
}
Ejemplo n.º 26
0
int		main()
{
	char	*str;

	str = "f**k duck muck puck";
	ft_strrev(str);
	ft_putstr(str);
	return(0);
}
Ejemplo n.º 27
0
char	*ft_strtrim(char const *s)
{
	char	*tmp;
	size_t	index;

	index = 0;
	tmp = (char *)malloc(sizeof(*s) * ft_strlen(s) + 1);
	if (tmp == NULL)
		return (NULL);
	ft_strcpy(tmp, s);
	while (ft_isspace42(tmp[index]))
		index++;
	tmp = ft_strsub(tmp, index, ft_strlen(tmp) - index);
	tmp = ft_strrev(tmp);
	index = 0;
	while (ft_isspace42(tmp[index]))
		index++;
	tmp = ft_strsub(tmp, index, ft_strlen(tmp) - index);
	tmp = ft_strrev(tmp);
	return (tmp);
}
Ejemplo n.º 28
0
int		main(void)
{
	char	*c1;
	char	*ch = "cette chaine de caracteres sera inversee svt exec fonction";
	int		a;
	int 	*e;

	a = 0;
	e = &a;
	ft_strrev(ch);
	return (0);
}
Ejemplo n.º 29
0
char				*ft_conv_u(char *nbr, char *base_from, char *base_to)
{
	int				i;
	unsigned int	convert;
	char			*res;

	i = 0;
	res = ft_strnew(65);
	convert = ft_atoui_base(nbr, base_from);
	while (convert > 0)
	{
		res[i++] = base_to[convert % ft_strlen(base_to)];
		convert /= ft_strlen(base_to);
	}
	res[i] = '\0';
	return (ft_strrev(res));
}
Ejemplo n.º 30
0
Archivo: ft_utoa.c Proyecto: Radugr7/ls
char	*ft_uctoa_base(unsigned char n, int base, char *trans_table)
{
	char	*aux;
	int		i;

	i = 0;
	aux = ft_strnew(15);
	if (n == 0)
		aux[0] = '0';
	while (n != 0)
	{
		aux[i++] = trans_table[n % base];
		n /= base;
	}
	aux = ft_strrev(aux);
	return (aux);
}