coding question

Dennis Melentyev dmelentyev at
Mon Apr 11 05:18:50 PDT 2005

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>

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]);
        nlines = nchars = 0; /* reinit for this file */
        while ((c = getc(fp)) != EOF) {
            if (c == '\n')
        printf("%ld %ld", nlines, nchars);
        if (fp != stdin)
            printf("%s", argv[i]);
        tlines += nlines;
        tchars += nchars;
        if (fp != stdin)
    if (argc > 2)
        printf("%ld %ld total\n", tlines, tchars);

Dennis Melentyev

More information about the Users mailing list