-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.c
More file actions
47 lines (42 loc) · 727 Bytes
/
Copy pathhelpers.c
File metadata and controls
47 lines (42 loc) · 727 Bytes
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
#include "monty.h"
/**
* is_number - helps to check the number
* @str: string
* @value: value
* Return: True or False / 1 or 0
*/
bool is_number(const char *str, int *value)
{
int sign = 1, result = 0;
if (str == NULL || *str == '\0')
return (false);
if (*str == '-')
{
sign = -1;
str++;
}
while (*str != '\0')
{
if (*str < '0' || *str > '9')
return (false);
result = result * 10 + (*str - '0');
str++;
}
*value = result * sign;
return (true);
}
/**
* clean_s - cleans the stack (free the stack)
* @stack: stack
* Return: Nothing
*/
void clean_s(stack_t *stack)
{
stack_t *current = stack, *next;
while (current != NULL)
{
next = current->next;
free(current);
current = next;
}
}