20180918-1 词频统计

作业要求参见 https://edu.cnblogs.com/campus/nenu/2018fall/homework/2126

本次作业代码地址:https://git.coding.net/YOS/words.git   代码为wf1.0.cpp文件。

发表博客,介绍上述“项目”中每个功能的重点/难点,展示重要代码片断,给出执行效果截图,展示你感觉得意、突破、困难的地方。

一,重点分析和代码实现:程序的主要功能是如何完成的。

1.读入文件数据:依次读入字母即可

void getword(char filename[]) {
    fp = fopen(filename, "r");
    memset(word, 0, sizeof(*word));
    i = 0;
    j = 0;
    while (!feof(fp)) {
        char c = fgetc(fp);
        if ((c >= 65 && c <= 90) || (c >= 97 && c <= 122)) {
            if (c < 97) {
                c += 32;
            }
            word[i] = c;
            i++;
            j=1;
        }
        else {
            if (j==1) {
                save(word, i);
                allsum++;
                j = 0;
            }
            i = 0;
        }
        
    }
    fclose(fp);
    return;
}

2.单词的区分

void save(char word[],int o) {

    for (i = 0; i <= sum; i++) {
        d = 0;
        for(int q = 0; q < o; q++) {
            if (words[i].a[q]!=word[q])
                d= 1;
        }
        if (d==0&&words[i].count==o){
            words[i].num++;
            break;
            //一个旧单词
        }
        
    }
    if (d != 0||sum==0) {
        for (i = 0; i < o; i++) {
            words[sum].a[i] = word[i];
            words[sum].num = 1;
            words[sum].count = o;
        }
        sum++;
    }    
    
}

3.现在我将单词都存到了结构体里,对其进行排序,输出即可完成功能1和功能2.

功能一实现截图如下

功能二实现截图如下

功能三运行结果如下

功能三会出现错误导致异常终止。

功能四未完成。

问题:展示你感觉得意、突破、困难的地方。

得意和突破的地方在于完成了一部分功能。

困难的地方在于各种错误以及调试。

psp 表格

原因:对任务的估计错误。

原文地址:https://www.cnblogs.com/zhouha0/p/9696846.html