-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtools.c
45 lines (38 loc) · 804 Bytes
/
tools.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
#include "shell.h"
/**
* is_positive_number - Checks if a string represents a positive number.
* @str: The string to check.
*
* Return: 1 if the string is a positive number, 0 otherwise.
*/
int is_positive_number(char *str)
{
int i;
/* Check if the input string is NULL */
if (!str)
return (0);
/* Iterate through the string to check if each character is a digit */
for (i = 0; str[i]; i++)
{
if (str[i] < '0' || str[i] > '9')
return (0);
}
return (1);
}
/**
* _atoi - Converts a string to an integer.
* @str: The string to convert.
*
* Return: The integer representation of the string.
*/
int _atoi(char *str)
{
int i, num = 0;
/* Iterate through the string to build the integer */
for (i = 0; str[i]; i++)
{
num *= 10;
num += (str[i] - '0');
}
return (num);
}