I searched but didn't find a solution. The program is supposed to count tabs, newlines and spaces.
#include <stdio.h>
int main(void)
{
int c,nl,tab,blank;
tab = 0;
blank = 0;
nl = 0;
while((c = getchar()) != EOF)
{
if(c == '\n');
nl++;
if(c == '\t');
tab++;
if(c == ' ');
blank++;
}
printf("newline: %d tab: %d blank: %d\n", nl,tab,blank);
return 0;
}
When I run this on FreeBSD using the ctrl-d to signal EOF, every variable is displayed with the same value. If I type "helloblank howtabareenteryouenterctrl-d" it displays newline as 18, tab as 18, blank as 18.
Is my code wrong? Obviously it is, but what's wrong?