File tree Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include "main.h"
2
+
3
+ /**
4
+ * _strncpy - Copies at most an inputted number
5
+ * of bytes from string src into dest.
6
+ * @dest: The buffer storing the string copy.
7
+ * @src: The source string.
8
+ * @n: The maximum number of bytes to copied from src.
9
+ *
10
+ * Return: A pointer to the resulting string dest.
11
+ */
12
+ char * _strncpy (char * dest , char * src , int n )
13
+ {
14
+ int i = 0 , src_length = 0 ;
15
+
16
+ while (src [i ++ ])
17
+ src_length ++ ;
18
+
19
+ for (i = 0 ; src [i ] && i < n ; i ++ )
20
+ dest [i ] = src [i ];
21
+
22
+ for (i = src_length ; i < n ; i ++ )
23
+ dest [i ] = '\0' ;
24
+
25
+ return (dest );
26
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ * File: 2-strncpy.c
3
+ * Auth: Brennan D Baraban
4
+ */
5
+
6
+ #include "holberton.h"
7
+
8
+ /**
9
+ * _strncpy - Copies at most an inputted number
10
+ * of bytes from string src into dest.
11
+ * @dest: The buffer storing the string copy.
12
+ * @src: The source string.
13
+ * @n: The maximum number of bytes to copied from src.
14
+ *
15
+ * Return: A pointer to the resulting string dest.
16
+ */
17
+ char *_strncpy(char *dest, char *src, int n)
18
+ {
19
+ int index = 0, src_len = 0;
20
+
21
+ while (src[index++])
22
+ src_len++;
23
+
24
+ for (index = 0; src[index] && index < n; index++)
25
+ dest[index] = src[index];
26
+
27
+ for (index = src_len; index < n; index++)
28
+ dest[index] = '\0';
29
+
30
+ return (dest);
31
+ }
You can’t perform that action at this time.
0 commit comments