home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / RCUTILS.ZIP / WRAP.C < prev    next >
C/C++ Source or Header  |  1991-09-30  |  2KB  |  67 lines

  1.  
  2. /********************************************************/
  3. /*                                                      */
  4. /*  Function: wrap80                                    */
  5. /*                                                      */
  6. /*   Purpose: Wraps lines >80 columns.  Assumes stdin   */
  7. /*            to stdout because it solves a problem     */
  8. /*            relating to 80 column screens.            */
  9. /*                                                      */
  10. /*   To build: CL /F 2000 /Lp /Fb wrap80.c              */
  11. /*                                                      */
  12. /*   To use:  wrap80                                    */
  13. /*                                                      */
  14. /*                                                      */
  15. /*      File: wrap80.c                                  */
  16. /*                                                      */
  17. /********************************************************/
  18.  
  19.         /* Include system calls/library routines/macros */
  20. #include <stdio.h>
  21.  
  22.         /* Define general variables */
  23. char read_ln[81];
  24.  
  25. main(argc, argv)
  26. int argc;
  27. char *argv[];
  28.   {
  29.  
  30.   if (argc != 1)
  31.     errex("\n\nProper usage: 'wrap80'\n\n");
  32.  
  33.   for (;;)      /* Until exit */
  34.   {
  35.     fgets(read_ln, sizeof(read_ln), stdin); // Up to 80 chars + \0
  36.     if ( feof(stdin) )  break;              // End of file ==> all done
  37.     fputs(read_ln, stdout);                 // Write it back out
  38.  
  39.     if ( read_ln[strlen(read_ln)-1] != '\n' ) // Did we get a newline?
  40.     {
  41.       register int ch;
  42.  
  43.       fputc('\n', stdout);                  // No, output one
  44.       if ( (ch=getc(stdin)) != '\n' )       // If next char is not the newline
  45.         ungetc(ch, stdin);                  // Push it back
  46.     }
  47.     if ( feof(stdin) )  break;              // End of file ==> all done
  48.   }
  49. }     /* of main */
  50.  
  51. /********************************************************/
  52. /*                                                      */
  53. /*  Function: errex                                     */
  54. /*                                                      */
  55. /*   Purpose: Prints an error message to the screen and */
  56. /*              exits.                                  */
  57. /*                                                      */
  58. /********************************************************/
  59.  
  60. errex(mess_ptr)
  61. char *mess_ptr;
  62. {
  63.  
  64. printf(mess_ptr);
  65. exit();
  66. }
  67.