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 >
Wrap
C/C++ Source or Header
|
1993-03-12
|
2KB
|
46 lines
/**********************************************************************/
/* REVERSE.C */
/* */
/* By matthew@uk.tele.nokia.fi (Matthew Faupel) */
/* */
/* This program indexes a wordlist according to word endings. */
/* Assuming this is compiled to be the program 'reverse', then: */
/* */
/* reverse </usr/dict/words | sort | reverse >words.r */
/* */
/* will give you the contents of /usr/dict/words sorted according */
/* to the word endings. */
/* */
/**********************************************************************/
#include <stdio.h>
main()
{
char lineBuffer[200];
int lineSize = 0;
int inChar;
while ((inChar = getchar()) != EOF)
{
/* This might need tweaking on some systems (e.g. PC) which use
* a double-byte line end sequence.
* Actually QC interprets \n correctly as LF+CR (LMB)
*/
if ((char) inChar == '\n')
{
while (lineSize > 0)
putchar( lineBuffer[--lineSize] );
putchar( '\n' );
}
else
lineBuffer[lineSize++] = inChar;
}
while (lineSize > 0)
putchar( lineBuffer[--lineSize] );
putchar( '\n' );
}
/* end */