-
Notifications
You must be signed in to change notification settings - Fork 0
/
MY_FUNCTIONS
85 lines (73 loc) · 1.27 KB
/
MY_FUNCTIONS
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
int my_strlen (char *s1)
{
int len;
len = 0;
while (s1[len++] != '\0');
return (len - 1);
}
char *my_concat(char *s1, char *s2)
{
char *temp;
int i;
int len1;
int len2;
len1 = my_strlen(s1);
len2 = my_strlen(s2);
temp = (char*)malloc(sizeof(char) * (len1 + len2 + 1));
if(temp == NULL)
return (0);
i = 0;
temp[len1 + len2] = '\0';
while (i < len1 + len2)
{
if (i < len1)
temp[i] = s1[i];
else
temp[i] = s2[i - len1];
i++;
}
return (temp);
}
// int my_strlen (char *s1)
// {
// int len;
// len = 0;
// while (s1[len++]);
// return (len - 1);
// }
// char *my_concat(char *s1, char *s2)
// {
// char *temp;
// int i;
// int len1;
// int len2;
// len1 = my_strlen(s1);
// len2 = my_strlen(s2);
// temp = (char*)malloc(sizeof(char) * (len1 + len2 + 2));
// if(temp == NULL)
// return (0);
// i = 0;
// temp[len1 + len2] = '\0';
// temp[len1] = '\n';
// while (i < len1 + len2)
// {
// if (i < len1)
// temp[i] = s1[i];
// else
// temp[i+1] = s2[i - len1];
// i++;
// }
// return (temp);
// }
// char *ft_concat_params(int argc, char **argv)
// {
// char *temp;
// int i;
// if(argc == 1)
// return (NULL);
// temp = argv[1];
// i = 2;
// while (i < argc)
// temp = my_concat(temp, argv[i++]);
// return (temp);
// }