尝试在一个二维字符数组中检查第二个二维字符数组中的关键字

Trying to check one 2d char array for keywords in a second 2d char array

我正在尝试将一个文本文件(在本例中为简历)与另一个包含一系列关键字的文件进行比较。我已将文件转换为二维数组,并试图检查简历中的关键字,但看起来它是在计算字符而不是单词。我不确定如何计算这里的单词数。任何帮助将不胜感激。这就是我正在尝试使用的:

        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.