-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.c
More file actions
92 lines (82 loc) · 2.1 KB
/
code.c
File metadata and controls
92 lines (82 loc) · 2.1 KB
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
87
88
89
90
91
92
#include "main.h"
/**
* is_printable - Evaluates if a char is printable
* @c: Char to be evaluated.
*
* Return: 1 if c is printable, 0 otherwise
*/
int is_printable(char c)
{
/* ASCII range of printable characters (32 to 126) */
if (c >= 32 && c < 127)
return (1);
return (0);
}
/**
* append_hexa_code - Append ascci in hexadecimal code to buffer
* @buffer: Array of chars.
* @i: Index at which to start appending.
* @ascii_code: ASSCI CODE.
* Return: Always 3
*/
int append_hexa_code(char ascii_code, char buffer[], int i)
{
char map[] = "0123456789ABCDEF";
/* If ascii_code is negative, make it positive */
if (ascii_code < 0)
ascii_code *= -1;
/* Add the escape sequence for a hex value to the buffer */
buffer[i++] = '\\';
buffer[i++] = 'x';
/* Get the first hexadecimal digit of ascii_code and add it to the buffer */
buffer[i++] = map[ascii_code / 16];
/* Get the second hexadecimal digit of ascii_code and add it to the buffer */
buffer[i] = map[ascii_code % 16];
return (3);
}
/**
* is_digit - Verifies if a char is a digit
* @c: Char to be evaluated
*
* Return: 1 if c is a digit, 0 otherwise
*/
int is_digit(char c)
{
/* Check if the character falls within the ASCII range of '0' to '9' */
if (c >= '0' && c <= '9')
/* If yes, return 1 to indicate that the character is a digit */
return (1);
return (0);
}
/**
* convert_size_number - Casts a number to the specified size
* @num: Number to be casted.
* @size: Number indicating the type to be casted.
*
* Return: Casted value of num
*/
long int convert_size_number(long int num, int size)
{
/* check if size is long */
if (size == S_LONG)
return (num);
/* check if size is short */
else if (size == S_SHORT)
return ((short)num);
return ((int)num);
}
/**
* convert_size_unsgnd - Casts a number to the specified size
* @num: Number to be casted
* @size: Number indicating the type to be casted
*
* Return: Casted value of num
*/
long int convert_size_unsgnd(unsigned long int num, int size)
{
if (size == S_LONG)
return (num);
else if (size == S_SHORT)
return ((unsigned short)num);
return ((unsigned int)num);
}