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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
#include <stdio.h>
#include <limits.h>
#include <string.h>
#include "ex00/ft_foreach.c"
#include "ex01/ft_map.c"
#include "ex02/ft_any.c"
#include "ex03/ft_count_if.c"
#include "ex04/ft_is_sort.c"
#include "ex06/ft_sort_string_tab.c"
#include "ex07/ft_advanced_sort_string_tab.c"
void f_fe(int x);
int f_ma(int x);
int f_len(char *x);
int f_cou(char *x);
int f_sor(int x, int y);
int f_lensort(char *a, char *b);
int main()
{
int tab[] = {1, 2, 3, 45, 67, 12, 89};
ft_foreach(tab, 7, &f_fe);
printf("\n------------------------\n");
int *mapped = ft_map(tab, 7, &f_ma);
for (int i = 0; i < 7; i++)
printf("%d ", mapped[i]);
free(mapped);
printf("\n------------------------\n");
char **ev = malloc(sizeof(char) * 5);
ev[0] = malloc(sizeof(char) * 32);
ev[1] = malloc(sizeof(char) * 32);
ev[2] = malloc(sizeof(char) * 32);
strcpy(ev[0], "bonjour");
strcpy(ev[1], "j");
strcpy(ev[2], "charles");
ev[3] = NULL;
printf("any %d", ft_any(ev, &f_len));
printf("\n------------------------\n");
printf("count if %d", ft_count_if(ev, 3, &f_cou));
printf("\n------------------------\n");
int sorted[10] = {1, 2, 3, 4, 5, 5, 6};
printf("sorted %d", ft_is_sort(sorted, 6, &f_sor));
printf("\n------------------------\n");
char **a = malloc(sizeof(char*) * 5);
a[0] = malloc(sizeof(char) * 32);
a[1] = malloc(sizeof(char) * 32);
a[2] = malloc(sizeof(char) * 32);
a[3] = malloc(sizeof(char) * 32);
strcpy(a[0], "bonjour");
strcpy(a[1], "je");
strcpy(a[2], "suis");
strcpy(a[3], "charles");
a[4] = NULL;
ft_sort_string_tab(a);
for (int i = 0; i < 5; i++)
printf("%s\n", a[i]);
printf("\n------------------------\n");
char **b = malloc(sizeof(char*) * 5);
b[0] = malloc(sizeof(char) * 32);
b[1] = malloc(sizeof(char) * 32);
b[2] = malloc(sizeof(char) * 32);
b[3] = malloc(sizeof(char) * 32);
strcpy(b[0], "bjour");
strcpy(b[1], "je");
strcpy(b[2], "suis");
strcpy(b[3], "carles");
b[4] = NULL;
ft_advanced_sort_string_tab(b, &f_lensort);
for (int i = 0; i < 5; i++)
printf("%s\n", b[i]);
}
void f_fe(int x)
{
printf("%d ", x + 2);
}
int f_ma(int x)
{
return (x * 2);
}
int f_len(char *x)
{
int counter = 0;
while (x[counter])
counter++;
return counter < 2;
}
int f_cou(char *x)
{
int counter = 0;
while (x[counter])
counter++;
return counter > 2;
}
int f_sor(int x, int y)
{
if (x == y)
return (0);
return x < y ? -1 : 1;
}
int f_lensort(char *a, char *b)
{
int i = 0;
int j = 0;
while (a[i])
i++;
while (b[j])
j++;
return (i - j);
}
|