> +dostrings(FILE *fp, const char *fname)
> +{
> +     unsigned char buf[BUFSIZ];
> +     int c, i = 0;
> +     off_t offset = 0;
> +
> +     while ((c = getc(fp)) != EOF) {
> +             offset++;
> +             if (isprint(c)) {
> +                     buf[i++] = c;
> +                     if (i == sizeof(buf) - 1) {
> +                             buf[i] = '\0';
> +                             printf("%8ld: %s\n", (long)offset - i - 1, buf);
> +                             i = 0;
> +                     }
> +             } else {
> +                     if (i >= 6) {
> +                             buf[i] = '\0';
> +                             printf("%8ld: %s\n", (long)offset - i - 1, buf);
> +                     }
> +                     i = 0;
> +             }
> +     }
> +     if (i >= 6) {
> +             buf[i] = '\0';
> +             printf("%8ld: %s\n", (long)offset - i - 1, buf);
> +     }
> +     if (ferror(fp))
> +             eprintf("%s read error:", fname);
> +}


Only other sugestion, this loop could be done better with a do while:

dostrings(FILE *fp, const char *fname)
{
        unsigned char buf[BUFSIZ];
        int c, i = 0;
        off_t offset = 0;
        do {
                offset++;
                if (isprint(c = getc(fp)))
                        buf[i++] = c

                if ((!isprint(c) && i >= 6) || i == sizeof(buf) - 1) {
                        buf[i] = '\0';
                        printf("%8ld: %s\n", (long)offset - i - 1, buf);
                        i = 0;
                }
        } while (c != EOF);
        
        if (ferror(fp))
                eprintf("%s read error:", fname);
        }
}
        
        -- 
Roberto E. Vargas Caballero
----------------------------
[email protected]
http://www.shike2.com

Reply via email to