The C and C++ code snippets monologue forum

The C, C++, Code, Coder, Coding Snippets Zone for Tenouk.com

 

 
It is currently Thu Sep 09, 2010 8:19 am

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: A simple program development
PostPosted: Sat Nov 11, 2006 1:53 pm 
Offline

Joined: Sat Nov 11, 2006 1:15 pm
Posts: 280
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: A simple program development


Code:
// Creating a working program skeleton…
#include <stdio>

int main()
{
   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:

Code:
Some prompt here...
test some text
test the output here...
Press any key to continue . . .

_________________
None


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 11, 2006 1:56 pm 
Offline

Joined: Sat Nov 11, 2006 1:15 pm
Posts: 280
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 . . .

_________________
None


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Skin by Lucas Kane