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

Re: coding question


From: Dennis Melentyev <dmelentyev@xxxxxxxxx>
Date: Mon, 11 Apr 2005 15:15:39 +0300

Terry Tree пишет:
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++;) {
Read the compiler comments. Count the ';'s in the line above.
PS. I did not checked any other row...

        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);
}



--
Dennis Melentyev
http://www.melentyev.kiev.ua/dennis



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