-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
107 lines (90 loc) · 2.8 KB
/
main.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fflores <fflores@student.21-school.ru> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/15 00:01:14 by fflores #+# #+# */
/* Updated: 2020/11/15 00:01:16 by fflores ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
/*
** Useful macros
*/
# define STRLEN(x) printf("`%s` = %d (%d)\n", x, ft_strlen(x), (int)strlen(x));
# define STRCMP(a, b) printf("`%s`:`%s` = %d (%d)\n", a, b, ft_strcmp(a, b), strcmp(a, b));
# define WRITE(s, x) printf("^%ld (`%s`:%ld)\n", ft_write(STDOUT_FILENO, s, x), s, x);
# define READ(b, x) r = ft_read(STDIN_FILENO, buffer, x); printf("`%s`:%ld\n", buffer, r);
# define DUP(s) tmp = ft_strdup(s); printf("`%s` (`%s`)\n", tmp, s); free(tmp); tmp = NULL;
/*
** Function prototypes
*/
int ft_strlen(char const *str);
int ft_strcmp(char const *s1, char const *s2);
char *ft_strcpy(char *dst, char const *src);
ssize_t ft_write(int fd, void const *buf, size_t nbyte);
ssize_t ft_read(int fd, void *buf, size_t nbyte);
char *ft_strdup(char const *s1);
/*
** Start !
*/
int main(void)
{
int i;
long r;
char buffer[100];
char *tmp;
char *tmp2;
r = 0;
i = 0;
while (i < 100)
buffer[i++] = 0;
printf("--strlen\n");
STRLEN("")
STRLEN("toto")
STRLEN("totototo")
STRLEN("0123456789abcdef")
STRLEN("42")
STRLEN("1")
printf("-done\n");
printf("\n--strcmp\n");
STRCMP("", "")
STRCMP("toto", "toto")
STRCMP("", "toto")
STRCMP("toto", "")
STRCMP("toto", "totobar")
printf("-done\n");
printf("\n--strcpy\n");
printf("`%s` (`toto`)\n", ft_strcpy(buffer, "toto"));
printf("`%s` (empty)\n", ft_strcpy(buffer, ""));
printf("`%s` (`long message`)\n", ft_strcpy(buffer, "long message"));
printf("-done\n");
printf("\n--write\n");
WRITE("toto", 4L)
WRITE("totototo", 4L)
WRITE("totototo", 8L)
WRITE("toto", 2L)
printf("-done\n");
printf("\n--read (Makefile)\n");
READ(buffer, 50)
READ(buffer, 25)
READ(buffer, 4)
READ(buffer, 26)
READ(buffer, 14)
READ(buffer, 0)
printf("-done\n");
printf("\n--ft_strdup\n");
tmp2 = ft_strdup("toto");
DUP(tmp2)
free(tmp2);
DUP("totobar")
DUP("long message")
DUP("")
printf("-done\n");
return (0);
}