-
Notifications
You must be signed in to change notification settings - Fork 0
/
tools.c
61 lines (54 loc) · 873 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "holberton.h"
/**
* rev_string - Reverse a string in the same memory location
*
* @s: Pointer of char variable
*/
void rev_string(char *s)
{
char *t;
int counter = 0, middle, temp, i, j, last, begin;
for (t = s; *t != '\0'; t++)
counter++;
middle = (counter % 2 == 0) ? (counter / 2) : ((counter - 1) / 2);
j = counter - 1;
for (i = 0; i < middle; i++)
{
last = s[j];
begin = s[i];
temp = last;
s[j] = begin;
s[i] = temp;
j--;
}
}
/**
* _abs - Computes the absolute value of an integer
*
* @n: Integer parameter
* Return: n (int)
*/
int _abs(int n)
{
if (n < 0)
{
return (n * -1);
}
else
{
return (n);
}
}
/**
* _strlen - Count the number of chars in a string
* @s: String given
*
* Return: Length of string
*/
int _strlen(const char *s)
{
int i = 0;
while (s[i] != '\0')
i++;
return (i);
}