A very simple C program completion process
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: Using simple steps on completing a C program by writing code-build the program-add code/functionalities-rebuild the program
To show: A very simple C program completion process
// Creating a working program skeleton
#include <stdio.h>
int main(void)
{
int count, charnum = 0;
printf("Some prompt here...\n");
while ((count = getchar()) != EOF)
{
if(count != ' ')
++charnum;
}
printf("test the output here...\n");
return 0;
}
Output example:
Some prompt here...
test some text
test the output here...
Press any key to continue . . .
// Add other functionalities by following the simple steps in program development
#include <stdio.h>
int main(void)
{
// 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 example:
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 . . .