-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstring.c
83 lines (79 loc) · 1.17 KB
/
string.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
#include "shell.h"
/**
* _putchar - check the code
* @c: a variable.
* Return: Always 0 (Success)
*/
int _putchar(char c)
{
write(1, &c, 1);
return (0);
}
/**
* _strcat - check the code
* @dest: pointer destination
* @src: pointer source
* Return: void.
*/
char *_strcat(char *dest, char *src)
{
int i;
int j;
for (i = 0; dest[i] != '\0'; i++)
;
for (j = 0; src[j] != '\0'; j++)
{
dest[i] = src[j];
i++;
}
dest[i] = '\0';
return (dest);
}
/**
* _strcpy - check the code
* @dest: pointer
* @src: pointer
* Return: void.
*/
char *_strcpy(char *dest, char *src)
{
int i;
for (i = 0; src[i] != '\0'; i++)
{
*(dest + i) = *(src + i);
}
dest[i] = '\0';
return (dest);
}
/**
* _strcmp - check the code
* @s1: pointer destination
* @s2: pointer source
* Return: void.
*/
int _strcmp(char *s1, char *s2)
{
int i;
for (i = 0; s1[i] != '\0' && s2[i] != '\0'; i++)
{
if (s1[i] != s2[i])
{
return (s1[i] - s2[i]);
}
}
return (0);
}
/**
* _strlen -return (*s != '\0' ? _strlen_recursion(s + 1) + 1 : 0); }
* @s: pointer.
* Return: void.
*/
int _strlen(char *s)
{
int len;
if (*s != '\0')
len = _strlen(s + 1) + 1;
else
len = 0;
return (len);
}