-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstr.c
More file actions
86 lines (73 loc) · 1.25 KB
/
str.c
File metadata and controls
86 lines (73 loc) · 1.25 KB
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
#include "shell.h"
/**
* string_cmp - performs lexicogarphic comparison of two strangs.
* @s: the first strang
* @s1: the second strang
*
* Return: negative if s < s1, positive if s > s1, zero if s == s1
*/
int string_cmp(char *s, char *s1)
{
int c;
c = (int)*s - (int)*s1;
while (*s)
{
if (*s != *s1)
{
break; }
s++;
s1++;
c = (int)*s - (int)*s1; }
return (c);
}
/**
* string_len - returns the length of a string
* @s: the string whose length to check
* Return: integer length of string
*/
int string_len(char *s)
{
int length = 0;
while (s[length])
{
length++; }
return (length);
}
/**
* string_cat - concatenates two strings
* @destination: the destination buffer
* @source: the source buffer
*
* Return: pointer to destination buffer
*/
char *string_cat(char *destination, char *source)
{
char *ptr = destination;
while (*ptr)
{
ptr++;
}
while (*source)
{
*ptr = *source;
ptr++, source++; }
*ptr = '\0';
return (destination);
}
/**
* string_cpy - copies a string
* @dest: the destination
* @src: the source
*
* Return: pointer to destination
*/
char *string_cpy(char *dest, char *src)
{
size_t ptr;
for (ptr = 0; src[ptr] != '\0'; ptr++)
{
dest[ptr] = src[ptr];
}
dest[ptr] = '\0';
return (dest);
}