-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmore_charfun.c
106 lines (101 loc) · 1.48 KB
/
more_charfun.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "shell.h"
/**
* _strcmp - Compare Two String
* @s1:String 1
* @s2:String 2
* Return: 0 If Identical Otherwise How Much Diffrent
*/
int _strcmp(char *s1, char *s2)
{
int cmp = 0, i, len1, len2;
len1 = _strlen(s1);
len2 = _strlen(s2);
if (s1 == NULL || s2 == NULL)
return (1);
if (len1 != len2)
return (1);
for (i = 0; s1[i]; i++)
{
if (s1[i] != s2[i])
{
cmp = s1[i] - s2[i];
break;
}
else
continue;
}
return (cmp);
}
/**
* _isalpha - Check if Alphabtic
*@c: Character
* Return: 1 If True 0 If Not
*/
int _isalpha(int c)
{
if (((c >= 97) && (c <= 122)) || ((c >= 65) && (c <= 90)))
{
return (1);
}
else
{
return (0);
}
}
/**
* _itoa - Convert Integer To Char
* @n: Int To Convert
* Return: Char Pointer
*/
char *_itoa(unsigned int n)
{
int len = 0, i = 0;
char *s;
len = intlen(n);
s = malloc(len + 1);
if (!s)
return (NULL);
*s = '\0';
while (n / 10)
{
s[i] = (n % 10) + '0';
n /= 10;
i++;
}
s[i] = (n % 10) + '0';
array_rev(s, len);
s[i + 1] = '\0';
return (s);
}
/**
* array_rev - Reverse Array
* @arr:Array To Reverse
* @len:Length Of Array
* Return: Void(Reverse Array)
*/
void array_rev(char *arr, int len)
{
int i;
char tmp;
for (i = 0; i < (len / 2); i++)
{
tmp = arr[i];
arr[i] = arr[(len - 1) - i];
arr[(len - 1) - i] = tmp;
}
}
/**
* intlen - Determine Length Of Int
* @num: Given Int
* Return: Length Of Int
*/
int intlen(int num)
{
int len = 0;
while (num != 0)
{
len++;
num /= 10;
}
return (len);
}