-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuilt_in_utils.c
More file actions
84 lines (66 loc) · 1.2 KB
/
Copy pathbuilt_in_utils.c
File metadata and controls
84 lines (66 loc) · 1.2 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
#include "main.h"
/**
* c_handler - Handle the Ctrl + C on the simple shell.
*
* @x: Unused int.
*
* Return: Void.
*/
void c_handler(int x)
{
UNUSED(x);
write(1, "\n$ ", 3);
}
/**
* number_of_tokens - Calculate the num of tokens.
*
* @tokens: Double pointer to tokens.
*
* Return: Return the quantity of the tokens.
*/
int number_of_tokens(char **tokens)
{
int number = 0;
while (tokens[number])
number++;
return (number);
}
/**
* find_points - Find double points in a string.
*
* @key: The string to search inside.
*
* Return: A new string, all the caracters behind that double points.
*/
char *find_points(char *key)
{
char *result = NULL;
size_t i = 0, j = 0;
while (key[i] != ':')
i++;
result = malloc((i + 1) * sizeof(char));
for (j = 0; j < i; j++)
result[j] = key[j];
result[j] = '\0';
return (result);
}
/**
* is_number - Validate if a string can be converted to a number.
*
* @str: String to valdidate.
*
* Return: Return 1 if the string contain only numbers, 0 otherwise.
*/
int is_number(char *str)
{
int i = 0, len = strlen(str);
while (str[i])
{
if (!(str[i] <= '9' && str[i] >= '0'))
break;
i++;
}
if (i == len)
return (1);
return (0);
}