Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- replchr.c
- S. Edward Dolan
- Monday, June 17 2019
- */
- #include <stdio.h>
- /*
- Replace all occurances of C with WHAT in SRC.
- */
- void replace(char* src, char c, char* what) {
- char* w;
- while (*src) {
- if (*src == c) {
- w = what; /* rewind the pointer */
- while (*w)
- putchar(*w++);
- ++src; /* skip the replaced char in src */
- continue; /* and don't print it */
- }
- putchar(*src++);
- }
- }
- int main(int argc, char** argv) {
- if (argc != 4) {
- fprintf(stderr,
- "Usage: %s SOURCE-STRING CHAR-TO-REPLACE SUBSTITUTE-STRING\n",
- argv[0]);
- return 1;
- }
- replace(argv[1], *argv[2], argv[3]);
- puts("");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement