minishell
get_numstr_base.c
Go to the documentation of this file.
1 /* ************************************************************************** */
2 /* */
3 /* ::: :::::::: */
4 /* get_numstr_base.c :+: :+: :+: */
5 /* +:+ +:+ +:+ */
6 /* By: kfujita <kfujita@student.42tokyo.jp> +#+ +:+ +#+ */
7 /* +#+#+#+#+#+ +#+ */
8 /* Created: 2022/04/23 02:10:07 by kfujita #+# #+# */
9 /* Updated: 2022/04/25 23:34:34 by kfujita ### ########.fr */
10 /* */
11 /* ************************************************************************** */
12 
13 #include <stdbool.h>
14 #include <stddef.h>
15 #include "ft_string.h"
16 
17 int get_numstr_base(char *buf, size_t num, int base, bool is_upper)
18 {
19  int tmp;
20  int last_len;
21  char c;
22 
23  if (num == 0)
24  return (0);
25  last_len = get_numstr_base(buf, num / base, base, is_upper);
26  tmp = num % base;
27  if (tmp < 10)
28  c = '0' + tmp;
29  else if (is_upper)
30  c = 'A' + tmp - 10;
31  else
32  c = 'a' + tmp - 10;
33  buf[last_len] = c;
34  return (last_len + 1);
35 }
int get_numstr_base(char *buf, size_t num, int base, bool is_upper)