-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend_record.c
77 lines (49 loc) · 1.13 KB
/
send_record.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
#include "./personal_record.h"
#include <stdio.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/msg.h>
main()
{
int fd;
int i;
char c[10];
int notfinish;
char garbage;
int msgq_id;
int msgq_flag;
msgbuf_t buf;
personal_record_t *rec;
rec = &(buf.prec);
msgq_flag = IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR;
msgq_id = msgget (IPC_PRIVATE, msgq_flag);
printf ("The message queue ID: %d\n", msgq_id);
notfinish = 1;
while (notfinish) {
printf ("Input a new record? (y/n): ");
scanf ("%s", c);
if (c[0]=='y' || c[0]=='Y') { //input a new record
printf ("Name: ");
scanf ("%s", &(rec->name));
printf ("ID number: ");
scanf ("%s", &(rec->ID));
printf ("Deposit: ");
scanf ("%d", &(rec->deposit));
printf ("\n");
buf.mtype = 1;
buf.notfinish = 1;
msgsnd (msgq_id, &buf, sizeof(msgbuf_t) - sizeof(long), 0);
}
else { //terminate execution
buf.mtype = 1;
buf.notfinish = 0;
msgsnd (msgq_id, &buf, sizeof(msgbuf_t) - sizeof(long), 0);
notfinish = 0;
}
}
return 0;
}//main()