帮看看,添加消息队列有错误,好像是字符类型不对。不知道怎么弄了。

img

#include<sys/types.h
#include<sys/ipc.h>
#include<sys/msg.h>
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<string.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<errno.h>
#define BUFSZ 512
#define MAXSIZE
struct message
{
long msg_type;
char msg_text [BUFSZ];
};

int main(void)
{

     int fd,i,size,len,qid;
     key_t key;

     struct message msg;
     struct message data;
     char *buf="hello world!";
     char buf_r[12];
                //d打开文件//
   if ( (fd=open("/home/panning/keshe/keshe2/read_text.c",O_RDWR,0600))<0)
   {
      perror("open:");
        exit(1);
          }
         //读取文//
         lseek(fd,0,SEEK_SET);
          if ( (size = read( fd, buf_r ,12))<0)
           {
                         perror("read");
                   exit(1);
             }

                                printf("read from file:%s\n",buf_r);
        //k值//
         if ( (key=ftok(".",'a'))== -1  )
                         {perror("ftok");
                     exit(1);
                        }
            //d创建队列//
                         if((qid=msgget(key,IPC_CREAT|0666))== 1)
                         {
                               perror("msgget");
                                            exit(1);
                                            }
                    printf("opened queue %d\n",qid);

                 msg=buf_r;
                    len=strlen(msg.msg_text);
                   // strcpy(msg.msg_type,buf_r);

                   //写入消//
                   if ( (msgsnd(qid,&msg,len,0))<0)
                                   {
                                                   perror("message posted");
                                                                   exit(1);
                                                                    }
                                  //读取//f
                                   if(msgrcv(qid,&msg,BUFSZ,0,0)<0)
          {
                            perror("msgrcv");

                              exit(1);
                            }
             printf("read formfile is:%s\n",buf_r);
                if ( close(fd) < 0)
                {
                        perror ("close:");
                        exit(1);
                     }
                exit(0);