-
Notifications
You must be signed in to change notification settings - Fork 0
/
more_functions.c
79 lines (70 loc) · 1010 Bytes
/
more_functions.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
#include "shell.h"
/**
* _atoi - function that convert a char to int
*
* @str: pointer to string
*
* Return: nomber of the converted char
*/
int _atoi(const char *str)
{
int num = 0, sign = 1, i = 0;
while (str[i] == ' ')
i++;
if (str[i] == '-')
{
sign = -1;
i++;
}
else if (str[i] == '+')
{
i++;
}
while (str[i] >= '0' && str[i] <= '9')
{
num = num * 10 + (str[i] - '0');
i++;
}
return (num * sign);
}
/**
*_isdigit - function that checks Is a digit
*
*@str: pointer to user input
*
*Return: 1 if a digit, else 0
*/
int _isdigit(char *str)
{
int i = 0;
while (str[i])
{
if (str[i] < 48 || str[i] > 57)
{
return (0);
}
i++;
}
return (1);
}
/**
* _free - function that free memory allocation
*
* @count: number of arguements
*
* Return: no return
*/
void _free(int count, ...)
{
int i = 0;
char *ptr;
va_list args_ptr;
va_start(args_ptr, count);
while (i < count)
{
ptr = va_arg(args_ptr, char *);
free(ptr);
i++;
}
va_end(args_ptr);
}