Skip to content

Commit 4499af0

Browse files
Code: added code for 2-strncpy.c
1 parent 9b014ee commit 4499af0

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include "main.h"
2+
3+
/**
4+
* _strncpy - A function that copies a string.
5+
*
6+
* @dest: The destination string
7+
* @src: The string to copy
8+
* @n: Number of times to copy
9+
*
10+
* Return: The copy of the src and append it to the dest
11+
* n number of times.
12+
*/
13+
14+
char *_strncpy(char *dest, char *src, int n)
15+
{
16+
int join = 0, i = 0;
17+
18+
while (src[i])
19+
{
20+
i++;
21+
}
22+
23+
while (join < n && src[join])
24+
{
25+
dest[join] = src[join];
26+
join++;
27+
}
28+
29+
while (join < n)
30+
{
31+
dest[join] = '\0';
32+
join++;
33+
}
34+
35+
return (dest);
36+
}

0 commit comments

Comments
 (0)