-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strcat.c
64 lines (56 loc) · 1.22 KB
/
ft_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
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
/*
* LIBRARY: <string.h>
*
* SYNOPSIS: concatenate strings (s2 into s1)
*
* DESCRIPTION:
* ============
* The strcat() and strncat() functions append a copy of the null-
* terminated string s2 to the end of the null-terminated string s1, then
* add a terminating `\0'. The string s1 must have sufficient space to hold
* the result.
*/
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
char *ft_strcat(char *s, const char *append)
{
int i;
int j;
i = 0;
j = 0;
while (s[i] != '\0')
{
i++;
}
while (append[j] != '\0')
{
s[i] = append[j];
i++;
j++;
}
s[i] = '\0';
return (s);
}
int main()
{
char s[50] = "Ghaiath ";
char append[50] = "Abdoush ";
printf("[1]\n\ndst befor ft_strcat is :%s\n", s);
printf("ft_strcat is :%s\n", ft_strcat(s, append));
printf("dst after ft_strcat is :%s\n\n\n", s);
/*
* NOTE:
* =====
* If you try to redo the whole process again like that,
* you need to determain the size of the dst and src strings,
* for example:
* dst[50];
* src[50];
* Or.... there will be a segmentation fault.
*/
printf("[2]\n\ndst befor ft_strcat is :%s\n", s);
printf("ft_strcat is :%s\n", ft_strcat(s, append));
printf("dst after ft_strcat is :%s\n", s);
return EXIT_SUCCESS;
}