DragonFly BSD
DragonFly users List (threaded) for 2005-04
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

coding question


From: Terry Tree <terry.tree@xxxxxxxxx>
Date: Mon, 11 Apr 2005 11:49:16 +0000

Can anyone tell me whats wrong here, I just can't get this piece of
code to compile.  After looking over it several times I can't figure
it out.

#include <stdio.h>

int
main(int argc, char **argv[])
{
    FILE *fp;
    long nchars;
    long nlines;
    long tchars;
    long tlines;
    int c, i;

    /* for each specified file */
    for (i = 1; i < argc; i++;) {
        if (argc == 1)
            fp = stdin;
        else if ((fp = fopen(argv[i], "r")) == NULL) {
            fprintf(stderr, "lc: cannot open %s\n", argv[i]);
            continue;
        }
        nlines = nchars = 0; /* reinit for this file */
        while ((c = getc(fp)) != EOF) {
            ++nchars;
            if (c == '\n')
                ++nlines;
        }
        printf("%ld %ld", nlines, nchars);
        if (fp != stdin)
            printf("%s", argv[i]);
        putchar('\n');
        tlines += nlines;
        tchars += nchars;
        if (fp != stdin)
            fclose(fp);
    }
    if (argc > 2)
        printf("%ld %ld total\n", tlines, tchars);
    exit(0);
}



[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]