-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSS_string1.c
More file actions
87 lines (75 loc) · 1.45 KB
/
SS_string1.c
File metadata and controls
87 lines (75 loc) · 1.45 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"
/**
* _strcpy - this function copies a string
* @dest: parameter showing the destination of the copied string
* @src: parameter showing the the source of the copied string
* Return: 0 if successful
*/
char *_strcpy(char *dest, char *src)
{
int a = 0;
if (dest == src || src == 0)
return (dest);
while (src[a])
{
dest[a] = src[a];
a++;
}
dest[a] = 0;
return (dest);
}
/**
* _strdup - this function duplicates a string by dynamically allocating memory
* to the duplicated string
* @str: function parameter showing the string to duplicate
* Return: 0 if successful
*/
char *_strdup(const char *str)
{
char *a;
int len = 0;
if (str == NULL)
return (NULL);
while (*str++)
len++;
a = malloc(sizeof(char) * (len + 1));
if (!a)
return (NULL);
for (len++; len--;)
a[len] = *--str;
return (a);
}
/**
* _puts - this function prints a null terminated string to standard output
* @str: function parameter showing the string to be printed
* Return: void
*/
void _puts(char *str)
{
int a = 0;
if (!str)
return;
while (str[a] != '\0')
{
_putchar(str[a]);
a++;
}
}
/**
* _putchar - this function writes the character to stdout
* @c: function parameter indicating The character to print
* Return: On success 1.
*/
int _putchar(char c)
{
static char b[WRITE_BUF_SIZE];
static int a;
if (c == BUF_FLUSH || a >= WRITE_BUF_SIZE)
{
write(1, b, a);
a = 0;
}
if (c != BUF_FLUSH)
b[a++] = c;
return (1);
}