-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_ft_split.c
90 lines (85 loc) · 2.5 KB
/
test_ft_split.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
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* test_ft_split.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jliew <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/07/04 05:16:40 by jliew #+# #+# */
/* Updated: 2020/07/17 17:32:07 by jliew ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "libft.h"
void print_split(char **split)
{
int i = 0;
if (!split)
{
printf("(null)\n");
return ;
}
if (!*split)
{
printf("[%s]\n", *split);
free(split);
return ;
}
printf("[");
for (i = 0; split[i]; i++)
{
printf("\"%s\", ", split[i]);
free(split[i]);
}
printf("%s", split[i]);
printf("]\n");
free(split[i]);
free(split);
}
int main(int argc, char **argv)
{
if (argc == 1)
{
printf("----------------------------------------\n");
printf(" char **ft_split(const char *s, char c)\n");
printf("----------------------------------------\n");
printf("usage [auto]:\n");
printf("1. a --run\n");
printf("usage [manual]:\n");
printf("1. a <string s> <char c>\n");
return (42);
}
else if (!strcmp(argv[1], "--run"))
{
printf("----------------------------------------\n");
printf(" char **ft_split(const char *s, char c)\n");
printf("----------------------------------------\n");
printf("1. ft_split(\"abababa\", '\\0')\n");
char **s = ft_split("abababa", '\0');
print_split(s);
printf("2. ft_split(\"\", '\\0')\n");
s = ft_split("", '\0');
print_split(s);
printf("3. ft_split(\"\", 'x')\n");
s = ft_split("", 'x');
print_split(s);
printf("4. ft_split(\"aaaaaaaa\", 'a')\n");
s = ft_split("aaaaaaaa", 'a');
print_split(s);
printf("5. ft_split(NULL, '\\0')\n");
s = ft_split(NULL, '\0');
print_split(s);
printf("6. ft_split(\"axbxc\", 'x')\n");
s = ft_split("axbxc", 'x');
print_split(s);
}
else
{
char *str = argv[1];
char c = argv[2][0];
char **split = ft_split(str, c);
print_split(split);
}
}