-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelper2.c
61 lines (55 loc) · 849 Bytes
/
helper2.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
#include "shell.h"
/**
* _rev - reverse a string
* @buff_boi_cpy: input string
*
* Return: nothing
*/
void _rev(char *buff_boi_cpy)
{
int i, j, k;
char temp;
k = _strlen(buff_boi_cpy);
j = k - 1;
for (i = 0; i < j; i++, j--)
{
temp = buff_boi_cpy[i];
buff_boi_cpy[i] = buff_boi_cpy[j];
buff_boi_cpy[j] = temp;
}
}
/**
* _itoa - convert integer to char array
* @num: int to convert
* Return: string to be written
*/
char *_itoa(int num)
{
int i = 0;
int j = 0;
int r;
int rep = num;
char *buff_boi;
buff_boi = malloc(120);
for (; j < 120; j++)
buff_boi[j] = '\0';
if (buff_boi == NULL)
return (NULL);
if (num < 0)
{
num = -num;
}
do {
r = num % 10;
buff_boi[i] = r + '0';
num /= 10;
i++;
} while (num != 0);
if (rep < 0)
{
buff_boi[i] = '-';
i++;
}
_rev(buff_boi);
return (buff_boi);
}