in reply to How to make this substitutions without splitting the strings?

Here's a reasonably fast one.
# include <stdio.h> # include <stdlib.h> # include <errno.h> int main(int argc, char **argv) { if (argc != 3) { fprintf(stderr, "Usage: %s <input_file> <comparison_file>\n", +argv[0]); exit(1); } FILE *in_file = fopen(argv[1], "r"); if (in_file == NULL) { perror(argv[1]); exit(1); } FILE *cmp_file = fopen(argv[2], "r"); if (cmp_file == NULL) { perror(argv[2]); exit(1); } for (;;) { char cmp = fgetc(cmp_file); char inp = fgetc(in_file); if (cmp == '-') { continue; } if (cmp == EOF || inp == EOF) { break; } putchar(inp); } fclose(in_file); fclose(cmp_file); exit(0); }
Compile:
gcc -O3 tr_big_string.c -o tr_big_string
Usage:
./tr_big_string ./big_string_file ./comparison_file

Replies are listed 'Best First'.
Re^2: How to make this substitutions without splitting the strings?
by Anonymous Monk on Aug 02, 2014 at 05:05 UTC

    For the serendipitous explorer: please do observe in above example code the oft-perpetrated C pitfall of forcing the fgetc() result to a char type. Return value of fgetc is int; this allows for end-of-file or error condition to be signaled via out-of-band value (EOF).