-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring_utils.c
More file actions
88 lines (75 loc) · 1.11 KB
/
string_utils.c
File metadata and controls
88 lines (75 loc) · 1.11 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
#include "main.h"
/**
*_strlen - counts
*@s: string or smtg
*Return: counter
*/
int _strlen(const char *s)
{
int counter = 0;
while (*s != '\0')
{
counter++;
s++;
}
return (counter);
}
/**
**_strcpy - copies
*@src: source
*@dest: destination
*Return: returns
*/
char *_strcpy(char *dest, char *src)
{
int i;
for (i = 0; src[i] != '\0'; i++)
{
dest[i] = src[i];
}
dest[i] = '\0';
return (dest);
}
/**
*_strdup - function returns pointer
*@str: string to copied
*Return: pointer to copied string
*/
char *_strdup(char *str)
{
int n;
char *p;
if (str == NULL)
{
return (NULL);
}
n = _strlen(str) + 1;
p = (char *)malloc(n * sizeof(char));
if (p == NULL)
return (NULL);
_strcpy(p, str);
return (p);
}
/**
* _putchar - writes character c to stdout
* @c: The character to print
*
* Return: must return 1 On success.
* On error, return -1, and errno is set appropriately.
*/
int _putchar(char c)
{
return (write(1, &c, 1));
}
/**
*printString - print strings
*@str: pointer to string to printed
*/
void printString(char *str)
{
while (*str)
{
_putchar(*str);
str++;
}
}