-
Notifications
You must be signed in to change notification settings - Fork 0
/
_strcat.c
35 lines (33 loc) · 637 Bytes
/
_strcat.c
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
#include "shell.h"
/**
* _strcat - function that takes 2 string and
* combines them
*
* @str1: first string
* @str2: second string
* Return: the combination of first and second string
* NULL on error case
*/
char *_strcat(const char *str1, const char *str2)
{
size_t len1, len2, iter;
char *newstr;
len1 = _strlen(str1);
len2 = _strlen(str2);
newstr = malloc(sizeof(char) * (len1 + len2 + 1));
if (!newstr)
return (NULL);
iter = 0;
while (iter < len1)
{
newstr[iter] = str1[iter];
iter++;
}
while (iter - len1 < len2)
{
newstr[iter] = str2[iter - len1];
iter++;
}
newstr[iter] = 0;
return (newstr);
}