码迷,mamicode.com
首页 > 其他好文 > 详细

WordCount

时间:2018-09-29 14:37:28      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:相同   ESS   指定   gif   回文   字符   adl   sdn   基本功   

     码云地址:https://gitee.com/qaqxx88/wc

1WordCount 需求说明

  (1)对源文件进行字符数,行数,单词数的统计并且放在与wc.exe相同目录下的result.txt 中

   (2)基本功能 

  wc.exe -c file.c     //返回文件 file.c 的字符数

  wc.exe -w file.c     //返回文件 file.c 的单词总数

  wc.exe -l file.c     //返回文件 file.c 的总行数

  wc.exe -o outputFile.txt     //将结果输出到指定文件outputFile.txt

2 解题思路,
  刚开始看到题目,由于当时只想着作出基本共功能,因此就想将每一个基本功能引用为一个方法,然后开始着手进行
3代码说明
3.1统计单词数
技术分享图片
 public static int WordNum(int wordcount, string file)

        {
            StreamReader sr = StrReadr(file);
            nchar = sr.Read();
            char[] symbol = {  , ,, \n };

            while ((nchar = sr.Read()) != -1)
            {

                foreach (char c in symbol)
                {
                    if (nchar == (int)c)
                    {
                        wordcount++;
                    }
                }
            }
wordNum

3.2 统计行数

技术分享图片
 1  public static int LineNum(int linecount, string file)
 2         {
 3             int i = 0;
 4             StreamReader sr = StrReadr(file);
 5             sr.BaseStream.Seek(0, SeekOrigin.Begin);
 6             string strline = sr.ReadLine();
 7             while (strline != null)
 8             {
 9                 i++;
10                 strline = sr.ReadLine();
11             }
12             sr.Close();
13             return i;
14 
15         }
wordlineNum

3.3统计字符串数

技术分享图片
 1    //tfile = file;
 2             //FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read);
 3             //StreamReader sr = new StreamReader(fs);
 4             StreamReader sr = StrReadr(file);
 5             while ((nchar = sr.Read()) != -1)
 6             {
 7                 charcount++;
 8             }
 9             sr.Close();
10             return charcount;
charNum

 4 测试

技术分享图片

5 总结

  通过此,是我认识到了很多,初步的学会使用了博客,码云,并且此次在写代码时,出现咯一定的失误,对语言的熟练度也还不高,认识到了不足。以后应多多动手,丰富经验。

 

6.  参考链接

如何使用码云    https://blog.csdn.net/s1120080286/article/details/79831146

如何安装git    https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/00137396287703354d8c6c01c904c7d9ff056ae23da865a000/

WordCount

标签:相同   ESS   指定   gif   回文   字符   adl   sdn   基本功   

原文地址:https://www.cnblogs.com/xxc518/p/9723086.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!