return 0;
}
程序B
#include <stdio.h>
#include <stdlib.h> //atof()
#include <string.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#define MSG_SIZE 32
#define MSG_TYPE 1
struct mymsgbuf
{
long mtype; //REQUIRED
char infos[MSG_SIZE];
};
int main()
{
key_t key = ftok("/home/cookie/msgqueue/Makefile", 1); int msgqueue = msgget(key, IPC_CREAT|IPC_EXCL|0666); if(msgqueue == -1)
{
printf("Message Queue Creation Failed");
return -1;
}
struct mymsgbuf msg_get;
if(msgrcv(msgqueue, &msg_get, MSG_SIZE, MSG_TYPE, 0) == -1) {
printf("Receive Message Failed");
return -1;
}
char* op;
struct mymsgbuf msg_put;
msg_put.mtype = MSG_TYPE;
memset(msg_s, 0, MSG_SIZE);
if((op = strchr(msg_s,'+')) != NULL)
{
float a = atof(msg_s);
float b = atof(op + 1);
float res = a + b;
sprintf(msg_s, "%f", res);