Comments on your program
COTTRELL, JAMES
cottrell at nbs-vms.arpa
Thu Nov 28 08:31:42 AEST 1985
/*
> Everybody I've shown this program to has *groaned* and complained
> about what a nasssty program it was... This program was written
> to help decode a bitnet routing table that I had been netcopy'd
> to me and didn't get translated into ascii. So after running dd
> over it, the line markers had disappeared into never never land.
> But from looking real closely at the file I could see that each
> line was supposed to start with ROUTE..... thus this program:
It doesn't work. Suppose the sequence `ROUROUTE' occurs. The second
`R' will not be recognized as the start of the sequence!
> #include <stdio.h>
>
> main()
> {
> register int r, o, u, t, e;
>
> while ((r = getchar()) != EOF) {
> if (r == 'R')
> if ((o = getchar()) == 'O')
> if ((u = getchar()) == 'U')
> if ((t = getchar()) == 'T')
> if ((e = getchar()) == 'E')
> printf("\nROUTE");
> else
> printf("ROUT%c", e);
> else
> printf("ROU%c", t);
> else
> printf("RO%c", u);
> else
> printf("R%c", o);
> else
> putchar(r);
> }
> putchar('\n');
> }
> --
> David Herron, cbosgd!ukma!david, david at UKMA.BITNET.
I thought of ways to use existing tools to do the job. How about this:
1) run thru `tr' to change all `R's to newlines. This gives you all
possible places where a line might start. Now run an `ex' script that
chex (wheat, corn, rice) each line begins with OUTE. If it doesn't,
then put back the R. Then for each line that begins with an R, join
it with the previous line. Finally, put back an R on each line.
So we have:
v/^OUTE/s/^/R/
g/^R/.-1,.j
g/^/s/^/R/
wq
If you're clever you might be able to work out a sed script.
> Experience is something you don't get until just after you need it.
To quote what you once said to me:`Now why didn't you think before posting?'
jim cottrell at nbs
*/
------
More information about the Comp.lang.c
mailing list