Οκ, since it's your first post I clicked on the link, but next time use the code tags
You have
Code:
while ( (c=getchar()) !=EOF); /* A semicolon!!*/
As I wrote in a comment, you have a semicolon there. What does this mean to a compiler?
It means, that you have a while loop, with a body of doing nothing!
Equivalently, you have this
Code:
while ( (c=getchar()) !=EOF)
;
which can be written like this
Code:
while ( (c=getchar()) !=EOF)
/*Do nothing*/;
So, you press a key, getchar brings it to the variable c, you check if it is not EOF and then you do nothing and go on to the next input, while you give EOF. So, when you do give EOF, you will say goodbye to this logically error loop. Then you will meet the if statements. But you won't enter none of them!
Why?
Because c is now EOF.
As a result, when you reach the printing part, you have the variables with their initial values.
So, how to fix it? Remove this semicolon.. But... Will this really work? My guess is no! Why?
Because you should use brackets (I really recommend using them, especially now that you are a beginner!!!!!!), or you should use if else instead of if.
Let's see what I mean:
( I have removed the semicolon )
Code:
while ( (c=getchar()) !=EOF)
if (c=='\n')
++new;
if (c=='\t')
++tabs;
if (c==' ')
++blanks;
Which is the body of the loop? Since, when we do not place brackets only the very next line of code is believed to be the body, the body of while is the very next if statement, which in turn, because it has no brackets, has as its body the ++new.
So, this code is equivalent to this code
Code:
while ( (c=getchar()) !=EOF)
{
if (c=='\n')
++new;
}
if (c=='\t')
++tabs;
if (c==' ')
++blanks;
which, as you can see, it's not what you want
But, if you had if else statements, then it would be ok.
What I say is this:
Code:
while ( (c=getchar()) !=EOF)
if (c=='\n')
++new;
else if (c=='\t')
++tabs;
else if (c==' ')
++blanks;
because the else is going together with the previous if.
But, what you should do at this stage of yours is this
Code:
while ( (c=getchar()) !=EOF)
{
if (c=='\n')
++new;
if (c=='\t')
++tabs;
if (c==' ')
++blanks;
}
Also, a good idea would be to use brackets at the if statements too.
Take home message:
Use brackets in your first steps! It's not something clever you need to practice much. As you gain experience, you can easily start omitting brackets. Omitting brackets, doesn't make you a better programmer. Just producing code with less lines (which in turn produces cleaner code). But first you have to learn how to code, in order to produce correct code and then you can improve the readability of it
Hope this helps