-
Notifications
You must be signed in to change notification settings - Fork 1
/
exitFile.c
73 lines (65 loc) · 1.2 KB
/
exitFile.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
#include "shell.h"
/**
* modify_exit - exit function.
* @argv: the filename
* @count:count number of error
* @av:the path name
* @err: the error message
* @simi: the array of the similar commands.
* Return: 1 if its true , 0 if false.
*/
int modify_exit(char **av, char *argv, int err, int count, char **simi)
{
if (av[1])
{
if (_nan(av[1]))
{
errno = err = 2;
print_stderr(argv, count, av[0], "Illegal number: ");
_putstr(av[1]), _putchar('\n');
return (2);
}
err = _stoi(av[1]);
}
free_2d(simi);
free_2d(av);
exit(err);
}
/**
* _nan - function to check if the array are NAN.
* @s: the string we want ( array of chars).
* Return: 1 if its true , 0 if false.
*/
int _nan(char *s)
{
int i;
for (i = 0; s[i]; i++)
if (s[i] < '0' || s[i] > '9')
return (1);
return (0);
}
/**
* _stoi - function to convert string to integer.
* @s: the string we want to convert ( array of chars) .
* Return: the integer which was converted.
*/
int _stoi(char *s)
{
int i, zero = 1, n = 0;
for (i = 0; s[i]; i++)
if (s[i] != '0')
{
zero = 0;
break;
}
if (zero)
return (0);
for (i = 0; s[i]; i++)
{
n += (s[i] - '0');
if (n != 0)
n *= 10;
}
n /= 10;
return (n);
}