-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring_util.c
116 lines (98 loc) · 1.66 KB
/
string_util.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
107
108
109
110
111
112
113
114
115
116
#include "shell.h"
/**
* hsh_strcmp - Comperes the given two strings.
* @str1: The first string
* @str2: The second string.
* Return: The compared strings.
*/
int hsh_strcmp(char *str1, char *str2)
{
while (*str1 && *str2)
{
if (*str1 != *str2)
return (*str1 - *str2);
str1++;
str2++;
}
return (0);
}
/**
* hsh_strcpy - Customize strcpy.
*
* @dest_file: Destination
* @src_file: Source file
*
* Return: @File Destinations
*/
char *hsh_strcpy(char *dest_file, char *src_file)
{
char *s = dest_file;
while (*src_file != '\0')
{
*dest_file = *src_file;
dest_file++;
src_file++;
}
*dest_file = '\0';
return (s);
}
/**
* hsh_parse - parsed string into tokens using delimiters.
*
* @str: string
* @delim: Delimiters
*
* Return: The parsed string.
*/
char **hsh_parse(char *str, char *delim)
{
char *token, **tokens;
int count = 0;
token = strtok(str, delim);
tokens = (char **)hsh_calloc(100, sizeof(char *));
if (!tokens)
{
free(tokens);
return (NULL);
}
while (token)
{
tokens[count] = token;
token = strtok(NULL, delim);
count++;
}
return (tokens);
}
/**
* hsh_strcat - function that concatenates two strings
*
* @dest_file: string Destinations.
* @src_file: string Source
*
* Return: Destination of joined strings.
*/
char *hsh_strcat(char *dest_file, char *src_file)
{
int i, j;
for (i = 0; dest_file[i] != '\0'; i += 1)
{}
for (j = 0; src_file[j] != '\0'; j += 1)
{
dest_file[i] = src_file[j];
i++;
}
dest_file[i] = '\0';
return (dest_file);
}
/**
* hsh_strlen - string length
* @str: string
* Return: result
*/
int hsh_strlen(char *str)
{
int i = 0;
while (str[i] != '\0')
i++;
return (i);
}