Word Count (C language)

1. Project address

https://github.com/namoyuwen/word-count

2. Project requirements

2.1 Project Description

   The Count Word
    1. achieve a simple and complete software tools (statistical characteristics of the source program).
    2. The unit test, regression test, performance test, the use of associated tools in the course of achieving the above program.
   3. Practice Personal Software Process (PSP), and gradually record their own time spent in each part of software engineering.

2.2 WC project requirements

wc.exe is a common tool, it can count the number of characters of text files, words, and lines. The project asked to write a command line program, to mimic the function of the existing wc.exe, and be expanded, given the number of characters in a programming language source files, words, and lines.

Implement a statistical program, the number of characters it can correct statistics program file, the number of words, lines, and also has other extended functions, and can handle multiple files quickly.
Specific functional requirements:
mode handles user needs to:

wc.exe [parameter] [file_name]

The basic list of features:

wc.exe -c file.c // returns the number of characters in the file file.c (Completed)

wc.exe -w file.c // Returns the number of files file.c word (Completed)

wc.exe -l file.c // file file.c the number of rows returned (Completed)

Extensions:
    -s recursive processing files that meet the conditions of the directory.
    -a return more complex data (line / space lines / comment lines).

Blank line: Bank format all control characters or spaces, if included code, no more than a displayable character, such as "{."

Line: Bank codes comprises more than one character.

Comment lines: lines of code instead of the Bank, and the Bank includes comments. An interesting example is that some programmers will add a comment behind a single character:

    } // NOTE
In this case, the line belongs to a comment line.

[file_name]: file or directory name, you can handle general wildcard.

Advanced Features:

 -x parameter. This parameter is used alone. If you have the command line parameters, the program will display a graphical interface, the user can select a single file through the interface, the program will display the file number of characters, lines, etc. All statistics.

Demand For example:
  wc.exe -s -a * .c


The number of lines of code returns the current directory and all subdirectories * .c files, the number of blank lines, comments, number of rows.

3. A description of problem-solving ideas

1. First, get this problem, because only the familiar C language, it is thought to do it in C language, the use of C language has been for some time what useless, so the time spent re familiar more time

2. difficulties and learning how to operate the key points of this document online when the subject is a focus for file operations for manipulating files were also learning

3. The subject is divided into four modules, the main function modules, and three basic functional blocks

4. The design and implementation process.

1. First, write three sub-functions, word count, number of words and number of lines

2. The main function calls the three functions

5. Code Description.

1. The main function

#include<stdio.h>
#include<stdlib.h>

Int Church (char * file);
int wordc (char * file);
int linec (char * file);

main int () {
the FILE * FP;
int CH, WO, Li;
char File [50]; // file address
printf ( "\ n Enter file address: \ n-");
Scanf ( "% S", File) ;

IF ((FP = the fopen (File, "R & lt")) == NULL)
{
the printf ( "file does not exist");
Exit (-1);
}
the else {
CH = charc (File);
WO = wordc (File );
Li = linec (file);
the printf ( "\ n-number of characters of the file% d \ n is the number of words% d \ n number of rows is% d \ n", CH, WO, Li);
}
}

2. The character counts

charc int (char * File) {
FILE * fp = NULL;
int charCount = 0;
IF ((fp = fopen (File, "r")) == NULL) {
printf ( "Failed to find the file \ n!");
Exit (-1);
}
char CH;
CH = fgetc (FP);
(! feof (FP)) {the while
CH = fgetc (FP); // read the characters in the document
charcount ++; // count the number of characters
}
fclose (FP);
return charCount;
}

3. The number of words statistics

wordc int (char * File) {
FILE * fp = NULL;
int wordcount = 0;
IF ((fp = fopen (File, "r")) == NULL) {
printf ( "Failed to find the file \ n!");
Exit (-1);
}
char CH;
int Word;

while (!feof(fp)) {
ch = fgetc(fp);
if (ch<'A' || (ch> 'Z'&&ch< 'a') || ch>'z')
{
word = 0;
}
else if (word == 0)
{
word = 1;
wordcount++;
}
}
return wordcount;
}

4. The number of rows statistics

int linec(char *file){//计算行数
int linecount=0;
char ch,li=0;
FILE *fp;
if ((fp=fopen(file,"r"))==NULL)
{
exit(-1);
}
ch = fgetc(fp);
while (!feof(fp))
{
if(ch=='\n')
linecount++;
li=ch;
}
if (li!='\n')
linecount++;
return linecount;
}

6. Test run.

1. Empty file

 

 2. a word file

 

 3. line Files

 

 

 4. A typical source file

 

 

7. Project Summary.

The personal project, spent a long time in the course of the review of the C language, but also made reference to many people's data and indirect, found his many shortcomings in the C language, but also in the idea of ​​coding very confusing, basically not consider important point.

The project yourself aware there are still many shortcomings, the revolution has not been completed, comrades must struggle. I also need to spend time each day in learning the language, acquire more knowledge. This time their actual PSP table also takes a lot longer than forecast

Mainly that of unskilled code and spend a lot of time in learning.

 

 

PSP Personal Software Process Stages Estimated time consuming (minutes) The actual time-consuming (minutes)
Planning plan 50 75
· Estimate Estimate how much time this task requires 20 15
Development Develop 120 150
Analysis Needs analysis (including learning new technologies) 30 120
·Design Spec Generate design documents 20 30
·Design Review Design review (and colleagues reviewed the design documents) 0 0
· Coding Standard Code specifications (development of appropriate norms for the current development) 5 5
·Design Specific design 30 60
·Coding Specific coding 100 160
·Code Review Code Review 30 45
·Test Test (self-test, modify the code, submit modifications) 10 5
Reporting report 10 30
·Test Report testing report 10 10
·Size Measurement Computing workload 30 60
·Postmortem & Process Improvement Plan Later summarized, and process improvement plan 20 30
total   485 795
       

Guess you like

Origin www.cnblogs.com/wenqinyi/p/12563649.html