-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.c
80 lines (73 loc) · 1.88 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
69
70
71
72
73
74
75
76
77
78
79
80
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* client.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: binurtas <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/14 18:50:01 by binurtas #+# #+# */
/* Updated: 2023/01/14 18:53:08 by binurtas ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk.h"
int ft_atoi(const char *nptr)
{
int i;
int result;
int pn;
i = 0;
result = 0;
pn = 1;
while ((nptr[i] >= 9 && nptr[i] <= 13) || (nptr[i] == 32))
i++;
if (nptr[i] == '+' || nptr[i] == '-')
{
if (nptr[i] == '-')
pn *= -1;
i++;
}
while (nptr[i] <= '9' && nptr[i] >= '0')
{
result = (result * 10) + (nptr[i] - '0');
i++;
}
return (result * pn);
}
void ft_send_bits(int pid, char c)
{
static int bit;
while (bit < 8)
{
if ((c & (0x01 << bit)) != 0)
kill(pid, SIGONE);
else
kill(pid, SIGZERO);
usleep(100);
bit++;
}
bit = 0;
}
int main(int ac, char **av)
{
int pid;
int i;
i = 0;
if (ac == 3)
{
pid = ft_atoi(av[1]);
if (pid == -1)
return (0);
while (av[2][i])
{
ft_send_bits(pid, av[2][i]);
i++;
}
ft_send_bits(pid, '\n');
}
else
{
ft_printf("Wrong format. You have to use like this :\n");
ft_printf("./client <PID> <MESSAGE>\n");
}
return (0);
}