home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_08_11 / 8n11053a < prev    next >
Text File  |  1990-09-18  |  754b  |  38 lines

  1.  
  2.  
  3. func()
  4. {
  5.     int msqid, msglen;
  6.     char string[80];
  7.     struct mssg  {
  8.         long mtype;
  9.         char mtext[BUFSIZ];
  10.     } msgbuf;
  11.  
  12.     /* Prompt user for a message to send */
  13.     printf("Enter message: ");
  14.     gets(msgbuf.mtext);
  15.  
  16.     /* Prompt user for a message type */
  17.     printf("Enter message type: ");
  18.     gets(string);
  19.     sscanf(string,"%ld",&(msgbuf.mtype));
  20.  
  21.     /* Set the message length */
  22.     msglen=strlen(msgbuf.mtext);
  23.  
  24.     /* Send the message.  The kernel will put
  25.      * the process to sleep if the message queue
  26.      * is full.
  27.     */
  28.     if (msgsnd(msqid, &msgbuf, msglen, 0) == -1)  {
  29.         /* The perror(3C) function prints the 
  30.          * text of the error number contained 
  31.          * in the external integer errno.
  32.         */
  33.         perror("msgsnd() failed: ");
  34.         exit(1);
  35.     }
  36. }
  37.  
  38.