-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.c
86 lines (73 loc) · 1.56 KB
/
utils.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "main.h"
/**
* is_printable - Function evaluates if a character is printable
* @c: Character under evaluation.
*
* Return: 1 if character is printable else 0
*/
int is_printable(char c)
{
if (c >= 32 && c < 127)
return (1);
return (0);
}
/**
* append_hexa_code - Function appends ascii in hexadecimal code to buffer.
* @buff: character array.
* @n: start append index.
* @ascii_code: ASCII CODE.
* Return: return value - 3
*/
int append_hexa_code(char ascii_code, char buff[], int n)
{
char map[] = "0123456789ABCDEF";
if (ascii_code < 0)
ascii_code *= -1;
buff[n++] = '\\';
buff[n++] = 'x';
buff[n++] = map[ascii_code / 16];
buff[n] = map[ascii_code % 16];
return (3);
}
/**
* is_digit - Function verifies if a character is a digit
* @c: Character to evaluated
*
* Return: 1 if character is digit else 0.
*/
int is_digit(char c)
{
if (c >= '0' && c <= '9')
return (1);
return (0);
}
/**
* convert_size_number - Function casting a number to specified size
* @num: Number to be casted.
* @size: cast type.
*
* Return: num
*/
long int convert_size_number(long int num, int size)
{
if (size == STR_LONG)
return (num);
else if (size == STR_SHORT)
return ((short)num);
return ((int)num);
}
/**
* convert_size_unsgnd - Function casting a number to specified size
* @num: Number to be casted.
* @size: cast type.
*
* Return: num
*/
long int convert_size_unsgnd(unsigned long int num, int size)
{
if (size == STR_LONG)
return (num);
else if (size == STR_SHORT)
return ((unsigned short)num);
return ((unsigned int)num);
}