C-尝试在第二个2D字符阵列中检查一个2D字符阵列中的关键字



我正在尝试比较一个文本文件,在这种情况下是简历,另一个文件中带有一系列关键字。我已经将文件变成了2D数组,并且正在尝试检查简历中的关键字,但是看起来它在计数字符而不是单词。我不确定如何仅在这里计算单词。任何帮助将不胜感激。这就是我要使用的方法:

        for (x = 0; x < 500; x++) {//starts and the first char of the resume, then moves to the next
            for (z = 0; z < 30; z++) {//runs through the first word
                if (resumeArray[x][z] == keywordArray[y][z]) {//if the word matches the keyword, then it's true
                    if(resumeArray[x][0] == keywordArray[y][0]){
                        if(resumeArray[x][z] == ' ')
                        keywordCount++;//if it's a true statement, then increase the keyword count
                    }
                }
            }
        }
        y++;//move on to the next keyword
    }

您应该像这样重写:

for (x = 0; x < 500; x++) {
        bool res = true;
        for (z = 0; z < 30; z++) {
            if (resumeArray[x][z] != keywordArray[y][z]) {
                res = false;
                break;
            }
        }
        if(res) keywordCount++;
    }

在上面的代码中,我使用res检查与关键字数组的数组中是否有任何不同。如果有任何区别,则无需检查更多并将res设置为false,并且不会增加keywordCount

最新更新