I'm trying to make a C program that will count and print the number of tabs, spaces, and lines input by the user. The problem is that when it prints those numbers, they are wildly off. Here is my program code:
int c, b, t, nl;
b, t, nl = 0, 0, 0;
while ((c = getchar()) != EOF)
{
if (c == '\b')
b++;
if (c == '\t')
t++;
if (c == '\n')
nl++;
}
printf("b=%d t=%d nl=%d\n", b, t, nl);
When I input some data from the terminal (3 lines, one space, one tab), the result is b=1899313536, t=32768, and nl=3.
int crather thanchar c.