./count should work. You'd obviously have to type something in, and eventually press CTRL-D to end the input, as you are expecting the file to end with EOF.
Aside from that:
Code:
if(lastchar != '\n')
{
++newlines; /* this is a bit of a semantic stretch, but it copes
* with implementations where a text file might not
* end with a newline. Thanks to Jim Stad for pointing
* this out.
*/
}
Not sure if that's correct - I guess it depends on what you want to achieve, I suppose.
And I would suggest using a switch() instead of chains of if, or at the very least use "else if" to avoid comparing things that you have already seen that it can not be - e.g. if the character is a tab, it obviously isn't a newline, so no need to do if (c == '\n') ... .
Edit: And, perhaps this can be simplified
Code:
int blanks, tabs, newlines;
int c;
int done = 0;
int lastchar = 0;
blanks = 0;
tabs = 0;
newlines = 0;
in this way:
Code:
int blanks = 0;
int tabs = 0;
int newlines = 0;
int c;
int done = 0;
int lastchar = 0;
--
Mats