-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.c
More file actions
70 lines (63 loc) · 1.59 KB
/
client.c
File metadata and controls
70 lines (63 loc) · 1.59 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* client.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bguzel <bguzel@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/30 18:31:31 by bguzel #+# #+# */
/* Updated: 2023/01/31 16:55:08 by bguzel ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk.h"
int ft_atoi(char *str)
{
int i;
int sign;
long result;
i = 0;
sign = 1;
result = 0;
while (str[i] == 32 || (str[i] >= 9 && str[i] <= 13))
i++;
if (str[i] == '-' || str[i] == '+')
{
if (str[i] == '-')
sign *= -1;
i++;
}
while (str[i] >= '0' && str[i] <= '9')
{
result = result * 10 + (str[i] - 48);
i++;
}
return (result * sign);
}
void ft_function(unsigned char a, int pid)
{
int j;
j = 7;
while (j >= 0)
{
if ((a >> j) & 1)
kill(pid, SIGUSR1);
else
kill(pid, SIGUSR2);
j--;
usleep(100);
}
}
int main(int ac, char **av)
{
int i;
int pid;
i = 0;
pid = ft_atoi(av[1]);
if (ac != 3)
return (0);
while (av[2][i])
{
ft_function(av[2][i], pid);
i++;
}
}