-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrings.c
99 lines (84 loc) · 1.33 KB
/
strings.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
#include "shell.h"
/**
* _putstring - prints a string
* @str: string to print
*/
void _putstring(char *str)
{
int i;
for (i = 0; str[i] != '\0'; i++)
_putchar(str[i]);
}
/**
* _strlen - finds length of a string
* @s: string
* Return: string length
*/
int _strlen(char *s)
{
unsigned int i;
if (s == NULL || *s == '\0')
return (0);
for (i = 0; s[i] != '\0'; i++)
;
return (i);
}
/**
* _strcmp - compares 2 strings
* @s1: string 1
* @s2: string 2
* Return: difference between strings
*/
int _strcmp(char *s1, char *s2)
{
int i;
for (i = 0; s1[i] != '\0'; i++)
{
if (s1[i] != s2[i])
{
return (s1[i] - s2[i]);
}
}
return (s2[i] - s1[i]);
}
/**
* _strcat - concatenates 2 strings
* @dest: dest string
* @src: string to add to dest
* Return: pointer to newly concatenated dest string
*/
char *_strcat(char *dest, char *src)
{
int i, j;
i = 0;
j = 0;
while (dest[i] != '\0')
i++;
dest[i] = '/';
i++;
while (src[j] != '\0')
{
dest[i] = src[j];
j++;
i++;
}
if (dest[i] != '\0')
dest[i] = '\0';
return (dest);
}
/**
* _strcpy - copies a string
* @src: string to be copied
* @dest: location of newly copied string
* Return: pointer to newly copied string
*/
char *_strcpy(char *dest, char *src)
{
int i;
for (i = 0; src[i]; i++)
{
dest[i] = src[i];
}
dest[i] = 0;
return (dest);
}