Compiler: Visual C++ Express Edition 2005
Compiled on Platform: Windows XP Pro SP2
Header file: Standard
Additional library: none/default
Additional project setting: Set project to be compiled as C
Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C Code (/TC)
Other info: none
To do: -
To show: Continue...
Code:
// Add other functionalities by following the
// simple steps in program development…
#include <stdio>
int main()
{
// printf("Some prompt here...\n");
// -----In the process: declare and initialize ----------
// -----each variable used------------------------
// -----Third: compile and run----------------
// -----Fourth: If there are errors, recompile and rerun----
// -----Finally, if there is no error, complete other part of-----
// -----the program, such as comments etc-------------
int count, charnum = 0, linenum = 0;
printf("Enter several line of texts.\n");
printf("Press Carriage Return then EOF to end.\n\n");
// -------------First: build the loop-----------
// while storing the character process
// not equal to the End Of File...
while((count = getchar()) != EOF)
{
// do the character count
if(count != ' ')
++charnum;
// and the line count...
if(count == '\n')
{
++linenum;
charnum = charnum -1;
}
}
// ----------Second: test the output---------------
printf("The number of line = %d\n", linenum);
printf("The number of char = %d\n", charnum);
return 0;
}
Output:Code:
Enter several line of texts.
Press Carriage Return then EOF to end.
First line of text
Second line of text
Third line of text
The number of line = 3
The number of char = 46
^CPress any key to continue . . .