#include <stdio.h>
int main(void)
{
int blanks, tabs, newlines,lastchar;
int c;
int done = 0;
lastchar =blanks = tabs =newlines = 0;
while(done == 0)
{
c = getchar();
if(c == ' ')
++blanks;
if(c == '\t')
++tabs;
if(c == '\n')
++newlines;
if(c == EOF)
{
if(lastchar != '\n')
{
++newlines;
}
done = 1;
}
lastchar = c;
}
printf("Blanks: %d\nTabs: %d\nLines: %d\n", blanks, tabs, newlines);
return 0;
}
类似的这样可以吗?lz可以自己去仿照写写看