zoukankan      html  css  js  c++  java
  • WC项目,实现一个统计程序

    程序处理用户需求的模式为:

    wc.exe[parameter][file_name]

    各个参数的意义:

    基本功能列表:

    wc.exe_c file.c;char count

    代码来源:http://www.mamicode.com/info-detail-2025316.html

    语言:c++

    平台:windows 平台,VS运行环境

    Bug和修改情况:无错,无修改

    Github地址:https://github.com/Fat-glouble/hello-world/blob/master/WC项目.txt

    代码:

    #include<iostream>
    #include<stdio.h>
    #include<string>
    
    using namespace std;
    FILE *file;
    int chars = 0, words = 0, lines = 1, s[500];
    char c;
    
    void T()
    {
    while ((c = fgetc(file)) != EOF)
    {
    chars++;
    if (((c <= 'z') && (c >= 'a')) || ((c <= 'Z') && (c >= 'A')) || ((c >= '0') && (c <= '9')))
    {
    words++;
    while ((c = fgetc(file)) != EOF)
    {
    chars++;
    if (((c <= 'z') && (c >= 'a')) || ((c <= 'Z') && (c >= 'A')) || ((c >= '0') && (c <= '9')))
    {
    }
    else if (c == '
    ')
    {
    s[lines] = 1;
    lines++;
    break;
    }
    else if (c == ' ')
    break;
    else
    {
    break;
    }
    }
    }
    else if (c == '/')
    {
    if ((c = fgetc(file)) == '/')
    {
    s[lines] = 2;
    fseek(file, -1L, SEEK_CUR);
    }
    }
    else if (c == '
    ')
    {
    if (s[lines] != 2)
    s[lines] = 1;
    lines++;
    }
    }
    if (s[lines] != 2)
    s[lines] = 1;
    }
    
    int main()
    {
    char name[30], b;
    int i;
    cout << " * 请输入源文件名:";
    for (;;)
    {
    cin >> name;
    if ((file = fopen(name, "r")) != NULL)
    break;
    else
    cout << " * 文件路径错误!请重新输入源文件名:";
    }
    T();
    fclose(file);
    cout << " 字符数:" << chars << endl;
    cout << " 单词数:" << words << endl;
    cout << " 行数 :" << lines << endl;
    for (i = 1; i <= lines; i++)
    {
    if (s[i] == 1)
    {
    if (i<10)
    cout << " 第" << i << "行为 代码行" << endl;
    else if (i<100)
    cout << " 第" << i << "行为 代码行" << endl;
    else
    cout << " 第" << i << "行为 代码行" << endl;
    }
    else if (s[i] == 2)
    {
    if (i<10)
    cout << " 第" << i << "行为 注释行" << endl;
    else if (i<100)
    cout << " 第" << i << "行为 注释行" << endl;
    else
    cout << " 第" << i << "行为 注释行" << endl;
    }
    }
    
    b = getchar();
    b = getchar();
    system("cls");
    return 0;
    }
    

      

  • 相关阅读:
    权限管理系统准备
    java启动线程时 extends与implements的一个差异
    spring中使用quartz时注入时出现的错误
    bat执行java程序 good
    bat下执行java程序报错处理
    SQLite.dll在xp中部署时的报错处理
    hdu 4277 USACO ORZ (dfs暴搜+hash)
    Java实现 蓝桥杯 算法训练 动态数组使用
    Java实现 蓝桥杯 算法训练 动态数组使用
    Java实现 蓝桥杯 算法训练 动态数组使用
  • 原文地址:https://www.cnblogs.com/zy12/p/7610661.html
Copyright © 2011-2022 走看看