File:  [MW Coherent from dump] / coherent / d / bin / rev.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Wed May 29 04:56:39 2019 UTC (7 years, 2 months ago) by root
Branches: MarkWilliams, MAIN
CVS tags: relic, HEAD
coherent

/*
 * Reverse the order of the characters
 * in every line of every file (or the
 * standard input if no files are given).
 */

#include <stdio.h>

#define	MAXLINE	1000

main(argc, argv)
char *argv[];
{
	FILE *fp;
	register int i;

	if (argc < 2)
		rev(stdin);
	else for (i=1; i<argc; i++)
		if ((fp = fopen(argv[i], "r")) == NULL)
			fprintf(stderr, "Cannot open `%s'\n", argv[i]);
		else {
			rev(fp);
			fclose(fp);
		}
	exit(0);
}

/*
 * Reverse the characters in every
 * line of the file described by
 * the given I/O stream.
 */
rev(stream)
FILE *stream;
{
	register char *ep;
	register c;
	static char line[MAXLINE];

	do {
		ep = line;
		while ((c=getc(stream))!='\n' && c!=EOF)
			*ep++=c;
		while (ep > line)
			putchar(*--ep);
		if (c=='\n')
			putchar('\n');
	} while (c != EOF);
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.