-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstring_functions.c
More file actions
110 lines (102 loc) · 1.65 KB
/
Copy pathstring_functions.c
File metadata and controls
110 lines (102 loc) · 1.65 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "main.h"
/**
* _strlen - determines the length of a string
* @str: the pointer pointing to a string
* Return: length of the string
*/
int _strlen(char *str)
{
int len = 0;
while (*str != '\0')
{
str++;
len++;
}
return (len);
}
/**
* countArguments - counts arguments from
* the command line
* @line: command line
* Return: number of arguments
*/
int countArguments(char *line)
{
int i = 0, search_spc = 1, num_args = 0;
while (line[i] != '\0')
{
if (line[i] != ' ' && search_spc == 1)
{
num_args++;
search_spc = 0;
}
if (line[i + 1] == ' ')
search_spc = 1;
i++;
}
return (num_args);
}
/**
* _strdup - duplicates a string to another one
* @str: the string
* Return: buffer
*/
char *_strdup(char *str)
{
int len = 0, j = 0;
char *buff;
if (!str)
return (NULL);
while (str[len] != '\0')
len++;
buff = malloc(sizeof(char) * (len + 1));
if (!buff)
return (NULL);
while (str[j] != '\0')
{
buff[j] = str[j];
j++;
}
buff[j] = '\0';
return (buff);
}
/**
* _strcpy - copies a string to another
* @src: The source string
* @dest: The destination string
* Return: On success, the destination string
*/
char *_strcpy(char *dest, char *src)
{
int l = 0, i;
while (src[l] != '\0')
l++;
for (i = 0; i <= l; i++)
dest[i] = src[i];
return (dest);
}
/**
* _strcat - concat a string to another
* @dest: The destination string
* @src: The source string
* Return: On success, the resulting string
*/
char *_strcat(char *dest, char *src)
{
int i = 0;
while (*dest != '\0')
{
dest++;
i++;
}
while (*src != '\0')
{
*dest = *src;
dest++;
i++;
src++;
}
*dest = '\0';
dest -= i;
return (dest);
}