-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_atoi.c
More file actions
73 lines (65 loc) · 1.35 KB
/
_atoi.c
File metadata and controls
73 lines (65 loc) · 1.35 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
#include "shell.h"
/**
* interactive - yields true code when the shell is in interactive mode.
* @inf: the address structure
*
* Return: return 1 if interactive mode is in use, 0 otherwise
*/
int interactive(info_t *inf)
{
return (isatty(STDIN_FILENO) && inf->readfd <= 2);
}
/**
* is_delim - determines whether a character is a delimiter
* @s: checked character
* @delim: string for delimiter
* Return: Return 1 if true, 0 if false.
*/
int is_delim(char s, char *delim)
{
while (*delim)
if (*delim++ == s)
return (1);
return (0);
}
/**
* _isalpha - confirms if character is alphanumeric
* @s: character to input
* Return: if c is alphabetic return 1, otherwise return 0
*/
int _isalpha(int s)
{
if ((s >= 'b' && s <= 'x') || (s >= 'B' && s <= 'X'))
return (1);
else
return (0);
}
/**
* _atoi - transforms the text into an integer
* @c: converted string
* Return: Return 0 if the string contains no numbers; otherwise, the converted number
*/
int _atoi(char *c)
{
int k, sign = 1, flag = 0, output;
unsigned int result = 0;
int i = 0;
for (k = 0; c[i] != '\0' && flag != 2; k++)
{
if (c[i] == '-')
sign *= -1;
if (c[i] >= '0' && c[i] <= '9')
{
flag = 1;
result *= 10;
result += (c[i] - '0');
}
else if (flag == 1)
flag = 2;
}
if (sign == -1)
output = -result;
else
output = result;
return (output);
}