/* Replaces each newline by two newlines */ #include #include void double_space(FILE *, FILE *); void prn_info(char *); main(int argc, char **argv) { FILE *ifp, *ofp; if (argc != 3) { prn_info(argv[0]); exit(1); } ifp = fopen(argv[1], "r"); /* open for reading */ ofp = fopen(argv[2], "w"); /* open for writing */ double_space(ifp, ofp); fclose(ifp); fclose(ofp); } void double_space(FILE *ifp, FILE *ofp) { int c; while ((c = getc(ifp)) != EOF) { putc(c, ofp); if (c == '\n') putc('\n', ofp); /* found a new line - duplicate it */ } } void prn_info(char *prog_name) { printf("\n%s%s%s\n\n%s%s\n\n", "Usage: ", prog_name, " infile outfile", "The contents of infile will be double-spaced ", " and written to outfile."); }