# Read program characters, number of lines, Word of the individual program

Source: Internet
Author: User

First, demand analysis:

Count the number of characters, number of lines and words in the program.

Idea Design:

By asking for personal understanding of the topic and the discussion of the students, I think that by using the functions of the line, the characters and the number of words are counted separately:

Statistics for the number of rows I used: int Isrand (char c, int &randnum).

I used this function for the statistics of words: int Isword (char c, int &wordnum). The default for a single letter and a number of letters is a word.

This function is used for the statistics of characters: int ischaracter (char c). Character statistics when two words between the space, brackets, equals sign and so on is counted as a single character.

Each of the three functions in the main function (main function) can be used to simply implement statistics on characters, lines, and words.

Second, the explanation of the key words:

Rand=0: Initialize the number of rows to zero, Rand means statistics for the number of rows.

Word=0: Initialize word to zero, word means the number of words.

Character=0: Initialize the number of characters to zero, character is the statistic of the characters.

Third, run the commissioning:

1. When all source programs are entered, the results and system statistics are the same as the number of rows: 63. The word is: 111. The total number of characters is: 905.

2. Use simple input to detect the correct statistics of characters and words.

Input: c = GetChar ()

Theoretical output:

Number of rows: 1

Word Output: 2

Character output: 13

Run:

3. Run tests on other sets of data:

Run

Iv. Personal Experience:

The basic requirement of the topic is not too difficult, but the requirement of basic knowledge is very high. At first thinking about the data to be detected stored in the file, but a full day of tossing the file data can not be opened in the vs2013 environment, But in vc6.0 the same code can be run, which requires me to actively to understand the VS2013 compilation environment, some of the problems do not understand the internet there are some explanations, need to understand and digest themselves.

Every time in programming to standardize their own code style, imitate other people's programming habits, slowly cultivate their habits, to adhere to. Standardizing the definition of their own functions, not only facilitates their own future reading, but also for others to read their own code to do the necessary work. Every programming is a workout for yourself.

Source:

#include <stdio.h>
#include <Windows.h>
int Isrand (char c, int &randnum)//Determine if line wrapping
{
if (c = = ' \ n ')
{
randnum++;
if (Randnum = = 1)
return 1;
Else
return 0;
}
Else
{
if (randnum>0)
Randnum = 0;
return 0;
}
}
int Isword (char c, int &wordnum)//determine if the word
{
if ((C >= ' a ' &&c <= ' z ') | | (c >= ' A ' &&c <= ' Z '))
{
wordnum++;
if (Wordnum = = 1)
return 1;
Else
return 0;
}
Else
{
if (wordnum>0)
Wordnum = 0;
return 0;
}
}
int Ischaracter (char c)//determine if the character
{
if ((c< ' 0 ' | | c> ' 9 ') && c! = ' \ n ')
return 1;
Else
return 0;
}
int main ()
{
System ("Color 9B");
int rand = 0, Word = 0, character = 0;//Initialize total number of rows, number of words, number of characters
int randnum = 0, Wordnum = 0;//randnum is the number of rows, Wordnum is the number of times
char c;
printf ("Please enter the program to be detected \ n");
while (RANDNUM&LT;2)//loop if not a blank line
{
c = GetChar ();
Rand + = Isrand (c, Randnum);
Word + = Isword (c, Wordnum);
Character + = Ischaracter (c);
}
printf ("Total number of rows:%d\n", Rand);
printf ("Number of words:%d\n", word);
printf ("Number of characters:%d", character);
System ("pause");
return 0;
}

Read program characters, number of lines, Word of the individual program

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.