home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / comm / tcp / amitcp / src / examples / rpc / msg / printmsg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-09  |  826 b   |  52 lines

  1. /* @(#)printmsg.c    2.1 88/08/11 4.0 RPCSRC */
  2. /*
  3.  * printmsg.c: print a message on the console
  4.  */
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7.  
  8. int printmessage(char *msg);
  9.  
  10. void
  11. main(int argc, char *argv[])
  12. {
  13.     char *message;
  14.  
  15.     if (argc < 2) {
  16.         fprintf(stderr, "usage: %s <message>\n", argv[0]);
  17.         exit(1);
  18.     }
  19.     message = argv[1];
  20.  
  21.     if (!printmessage(message)) {
  22.         fprintf(stderr, "%s: sorry, couldn't print your message\n",
  23.             argv[0]);
  24.         exit(1);
  25.     } 
  26.     printf("Message delivered!\n");
  27. }
  28.  
  29. /*
  30.  * Print a message to the console.
  31.  * Return a boolean indicating whether the message was actually printed.
  32.  */
  33. int 
  34. printmessage(char *msg)
  35. {
  36.     FILE *f;
  37. #ifdef amigados
  38.     f = stdout;
  39. #else
  40.     f = fopen("/dev/console", "w");
  41. #endif
  42.     if (f == NULL) {
  43.         return (0);
  44.     }
  45.     fprintf(f, "%s\n", msg);
  46. #ifndef amigados
  47.     fclose(f);
  48. #endif
  49.     return(1);
  50. }
  51.  
  52.