#include #include #include /* RMCR : routine to remove carriage return (CR = \r) characters from files. ("\r" shows up as "^M" in the editors.) Format: $ rmcr [-v] [ input file [ output file ] ] If no files are specified, stdin and stdout are used. If only one file is named, it is assumed to be the input file. Wild cards are not allowed. */ /* Modification History: 17 june 1992: creation (a.c.raugh) 21 July 1992: added file error handling (acr) 27 sept 1993: modified messages (acr) 21 nove 1994: added "silent" mode (acr) 21 July 1995: replaced -s with -v and reversed default behavior (acr) */ main(argc,argv) int argc; char *argv[]; { extern int errno; /* system error code */ FILE *infile; /* input file name */ FILE *outfile; /* output file name */ int c; /* input character */ int rcount; /* record count */ int maxlen; /* maximum line length */ int ccount; /* line character count */ int i; /* loop/subscript */ int verbose; /* flag value */ /* Open files as needed (default to standard input and output); */ if (argc > 4) { fprintf (stderr,"Usage: rmcr [-s] [input [output] ]\n"); exit(0); } infile = outfile = NULL; verbose = 0; for (i=1; i maxlen) ? ccount : maxlen; ccount = 0; } } } /* loop through characters */ /* Report results to standard error: */ if (verbose) { fprintf (stderr, "\nrmcr: %d records written; longest record %d characters\n\n", rcount,maxlen); } /* Close files: */ fclose(infile); fclose(outfile); return 0; }