Skip to content

Instantly share code, notes, and snippets.

@veganaize
Last active June 20, 2021 21:10
Show Gist options
  • Save veganaize/383a40ad5149e000374a5600dca22291 to your computer and use it in GitHub Desktop.
Save veganaize/383a40ad5149e000374a5600dca22291 to your computer and use it in GitHub Desktop.
Replace character in stream
#include <stdio.h>
int main(int argc, char **argv)
{
int c;
FILE *fp = stdin;
/* Input filename on command line ? */
if (argc > 1) {
fp = fopen(argv[1], "r");
if (fp == NULL) {
fputs("Unable to open file.", stderr);
return 1;
}
}
/* Replace character in stream */
while (!feof(fp)) {
c = getc(fp);
putchar(c == '#' ? '+' : c);
}
return 0;
}
@veganaize
Copy link
Author

veganaize commented Jun 20, 2021

Usage:

middleman
middleman infile
middleman <infile
middleman >outfile
middleman infile >outfile
middleman <infile >outfile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment