Working through H&K... Strange Output
Hi All!
I'm working though H&K, specifically, I'm looking at exercise 1-8 (Write a program that counts blanks, tabs, and lines.) My code seems to count spaces and lines correctly, but for some reason the number of tabs always ends up at around 4,100,000.
Any ideas as to what might be wrong?
Code:
#include <stdio.h>
/*Exerceise 1-8 from H&K- counts spaces, tabs, and lines */
int main () {
int c, blank, tab, newline = 0;
while ((c = getchar()) != EOF) {
if (c == ' ')
++blank;
else if (c == '\t')
++tab;
else if (c == '\n')
++newline;
}
printf("\nSpaces: %d\nTabs: %d\nLines: %d\n", blank, tab, newline);
}
Thanks for any help you may be able to render in advance!