-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.c
68 lines (61 loc) · 1.51 KB
/
client.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* client.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abdel-ou <abdel-ou@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/06 13:04:03 by abdel-ou #+# #+# */
/* Updated: 2022/12/25 16:37:13 by abdel-ou ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk.h"
void cov(int nb, char *bit)
{
int i;
i = 0;
if (nb < 2)
{
while (i < 7)
{
bit[i] = bit[i + 1];
i++;
}
bit[7] = nb + 48;
}
else
{
cov(nb / 2, bit);
cov(nb % 2, bit);
}
}
void char_send(char *pid, int nb)
{
int i;
char *bit;
i = 0;
bit = ft_strdup("00000000");
cov(nb, bit);
while (i < 8)
{
if (bit[i] == '0')
kill(ft_atoi(pid), SIGUSR1);
if (bit[i] == '1')
kill(ft_atoi(pid), SIGUSR2);
i++;
usleep(300);
}
free(bit);
}
int main(int argc, char **argv)
{
int i;
(void)argc;
i = 0;
while (argv[2][i])
{
char_send(argv[1], (unsigned char)argv[2][i]);
i++;
}
return (0);
}