-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5b) i) fifo client sde.c
More file actions
49 lines (41 loc) · 1.25 KB
/
5b) i) fifo client sde.c
File metadata and controls
49 lines (41 loc) · 1.25 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
// fifo client side program
// works in devcpp
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#define FIFO_FILE "fifo_twoway"
int main() {
int fd;
int end_process;
int stringLen;
int read_bytes;
char read_buf[80];
char end_str[5];
printf("FIFO_CLIENT: Send messages, infinitely, to end enter \"end\"\n");
fd = open(FIFO_FILE, O_CREAT|O_RDWR);
strcpy(end_str, "end");
while (1) {
printf("Enter a string: ");
fgets(read_buf, sizeof(read_buf), stdin);
stringLen = strlen(read_buf);
read_buf[stringLen - 1] = '\0';
end_process = strcmp(read_buf, end_str);
if (end_process != 0) {
write (fd, read_buf, strlen(read_buf));
printf("FIFOCLIENT: Sent string: \"%s\" and string length is %d\n", read_buf, (int)strlen(read_buf));
read_bytes = read(fd, read_buf, sizeof(read_buf));
read_buf[read_bytes] = '\0';
printf("FIFOCLIENT: Received string: \"%s\" and length is %d\n", read_buf, (int)strlen(read_buf));
}
else {
write(fd, read_buf, strlen(read_buf));
printf("FIFOCLIENT: Sent string: \"%s\" and string length is %d\n", read_buf, (int)strlen(read_buf));
close(fd);
break;
}
}
return 0;
}