home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / r / reverse.zip / REVERSE.C < prev    next >
C/C++ Source or Header  |  1993-03-12  |  2KB  |  46 lines

  1. /**********************************************************************/
  2. /* REVERSE.C                                                          */
  3. /*                                                                    */
  4. /*   By matthew@uk.tele.nokia.fi (Matthew Faupel)                     */
  5. /*                                                                    */
  6. /*   This program indexes a wordlist according to word endings.       */
  7. /*   Assuming this is compiled to be the program 'reverse', then:     */
  8. /*                                                                    */
  9. /*       reverse </usr/dict/words | sort | reverse >words.r           */
  10. /*                                                                    */
  11. /*   will give you the contents of /usr/dict/words sorted according   */
  12. /*   to the word endings.                                             */
  13. /*                                                                    */
  14. /**********************************************************************/
  15.  
  16. #include <stdio.h>
  17.  
  18. main()
  19. {
  20.   char lineBuffer[200];
  21.   int  lineSize = 0;
  22.   int  inChar;
  23.  
  24.   while ((inChar = getchar()) != EOF)
  25.     {
  26.       /* This might need tweaking on some systems (e.g. PC) which use
  27.        * a double-byte line end sequence.
  28.        * Actually QC interprets \n correctly as LF+CR (LMB)
  29.        */
  30.       if ((char) inChar == '\n')
  31.     {
  32.       while (lineSize > 0)
  33.         putchar( lineBuffer[--lineSize] );
  34.       putchar( '\n' );
  35.     }
  36.       else
  37.     lineBuffer[lineSize++] = inChar;
  38.     }
  39.   while (lineSize > 0)
  40.     putchar( lineBuffer[--lineSize] );
  41.   putchar( '\n' );
  42. }
  43. /* end */
  44.  
  45.  
  46.