Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: How to make this substitutions without splitting the strings?

by Anonymous Monk
on Jul 28, 2014 at 11:53 UTC ( [id://1095337]=note: print w/replies, xml ) Need Help??


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).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1095337]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-04-16 05:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found