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

WC项目

时间:2016-10-22 00:01:57      阅读:332      评论:0      收藏:0      [点我收藏+]

标签:open   输入   close   out   space   rcp   #include   name   end   

 #include<iostream>
 #include<fstream>
 #include<string>
 #include<Windows.h>
 using namespace std;
 void main()
  {
      char word[150][15];
      int AllChar = 0, NoteSize = 0, Row = 1, WordSize = 0;
     char a[15], c, file[15];
     int i = 0, j = 0;
     FILE *fp;
     cout << "#结束输入" << endl;
     cin >> file;
     while (1)
     {
         if (file[0] == ‘#‘)
             break;
         fp = fopen(file, "r");
         if (fp == NULL)
         {
             cout << "the file:y.txt not found!" << endl;
             exit(-1);
         }
         c = fgetc(fp);
         AllChar++;
         if (c == ‘/‘)
         {
             c = fgetc(fp);
             AllChar++;
             if (c == ‘/‘)
                 NoteSize++;
         }
         c = fgetc(fp);
         AllChar++;
         while (c != EOF)
         {
             if ((c >= ‘a‘&&c <= ‘z‘) || (c >= ‘A‘) && (c <= ‘Z‘))
             {
                 a[i] = c;
                 c = fgetc(fp);
                 AllChar++;
                 i++;
                 continue;
             }
             else if (c == ‘/‘)
             {
                 c = fgetc(fp);
                 AllChar++;
                 if (c == ‘/‘)
                 {
                     c = fgetc(fp);
                     AllChar++;
                     NoteSize++;
                     continue;
                 }
             }
             else
             {
                 if (c == ‘\n‘)
                 {
                     Row++;
                 }
                 if (i != 0)
                 {
                     a[i] = ‘\0‘;
                     strcpy_s(word[j], a);
                     j++;
                     i = 0;
                 }
                 c = fgetc(fp);
                 AllChar++;
             }
         }
         if (i != 0)
         {
             a[i] = ‘\0‘;
             strcpy_s(word[j], a);
             j++;
         }
         fclose(fp);
         WordSize = j;
         cout << "行数:" << Row << endl;
         cout << "字符数:" << AllChar << endl;
         cout << "单词数:" << WordSize << endl;
         cout << "注释行:" << NoteSize << endl;
         cin >> file;
     }
 }

WC项目

标签:open   输入   close   out   space   rcp   #include   name   end   

原文地址:http://www.cnblogs.com/1409030208l/p/5986246.html

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