**
* On-line, word and character input is counted. We will be simplified definition of the word, that the word is a sequence of characters that does not contain spaces, tabs \ t and newline
**. For example: "a + b + c", that is a word which consists of five symbols. Another example: "xy abc", as two words, six characters. Ctrl + z input end (Tip: ch = EOF with or ch = - 1 as the loop condition!!).
** Output format requirements: "Lines =% d \ nWords =% d \ nChars =% d \ n"
run the following example:
Hi ~
Good Moring!
The I'm Julie.
Lines=3
Words=5
Chars=28
#include <stdio.h>
int main ( )
{
char ch = '\0';
//循环接受字符
int l = 0,w = 0,c = 0;
while (scanf("%c",&ch) != EOF)
{
c++;
if (ch==' '||ch=='\n') {
w++;
}
if (ch=='\n') {
l++;
}
}
printf("Lines=%d\nWords=%d\nChars=%d\n",l,w,c);
return 0;
}
Note:
1. The receiving transducer line can not be used chOr 13 '
' can only ch'\ the n-'
2 · *** *** EOF by -1 is a meaning in one is enough, end of file , no additional output in the compiler inside, but the operating system can (as I do not know what currently)