Last active
June 20, 2021 21:10
-
-
Save veganaize/383a40ad5149e000374a5600dca22291 to your computer and use it in GitHub Desktop.
Replace character in stream
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: