coding question
Terry Tree
terry.tree at gmail.com
Mon Apr 11 04:50:14 PDT 2005
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);
}
More information about the Users
mailing list