-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcalc.c
57 lines (54 loc) · 835 Bytes
/
calc.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
#include "holberton.h"
/**
* __atoi - take string, and find number the starts at point n
* @s: string to read
* @n: position to begin reading number
*
* Return: Number parsed
*/
int __atoi(const char *s, int n)
{
int number, i;
i = number = 0;
while (s[n + i] <= '9' && s[n + i] >= '0')
{
if (i > 0)
number *= 10;
number += s[n + i] - '0';
i++;
}
return (number);
}
/**
* str_len - find the str len
* @str: a pointer to a str
*
* Return: length of string
*/
int str_len(char *str)
{
int i;
i = 0;
while (str[i] != '\0')
i++;
return (i);
}
/**
* _revstr - find the str len
* @s: a pointer to a str
*
* Return: length of string
*/
void _revstr(char *s)
{
int len, i;
char tmp;
i = 0;
len = str_len(s) - 1;
while (i <= len / 2)
{
tmp = s[len - i];
s[len - i] = s[i];
s[i++] = tmp;
}
}