-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadder.c
More file actions
36 lines (28 loc) · 734 Bytes
/
adder.c
File metadata and controls
36 lines (28 loc) · 734 Bytes
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
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#define PIPE_NAME_ADDER "adder_pipe"
int main(int argc, char *argv[])
{
int fd_read = open(PIPE_NAME_ADDER, O_RDONLY);
int fd_write = open(PIPE_NAME_ADDER, O_WRONLY);
while (1)
{
char buffer[100];
read(fd_read, buffer, sizeof(buffer));
if (strcmp(buffer, "exit") == 0)
{
close(fd_read);
close(fd_write);
exit(EXIT_SUCCESS);
}
double num1, num2, result;
sscanf(buffer, "%lf %lf", &num1, &num2);
result = num1 + num2;
write(fd_write, &result, sizeof(result));
usleep(100000);
}
return 0;
}