shortshort way of reversing the lines in a file

Stephen J. Muir stephen at dcl-cs.UUCP
Tue Sep 3 00:26:33 AEST 1985


In article <822 at lll-crg.UUCP> bandy at lll-crg.UUCP (Andrew Scott Beals) writes:
>Recently, some Gentleman from the UK posted a program that reversed
>the lines in a file. I figured that I should post this somewhat 
>shorter solution.

At least give me the credit -- see the first line of the body of the article.

>#include <stdio.h>
>
>main() {
>    char	foo[BUFSIZ];
>
>    if(gets(foo) == NULL) return;
>    main();
>    puts(foo);
>}

This assumes you have enough memory to hold the entire file.  Also, you have to
read it all -- I wrote the program MAINLY because I wanted a QUICK way to scan
backwards.
-- 
UUCP:	...!seismo!mcvax!ukc!dcl-cs!stephen
DARPA:	stephen%lancs.comp at ucl-cs	| Post: University of Lancaster,
JANET:	stephen at uk.ac.lancs.comp	|	Department of Computing,
Phone:	+44 524 65201 Ext. 4599		|	Bailrigg, Lancaster, UK.
Project:Alvey ECLIPSE Distribution	|	LA1 4YR



More information about the Comp.sources.unix mailing list