文字列「death」を、テキスト ファイル内の任意の 5 文字の文字列と比較する必要があります。
関数が機能しているようには見えませんが、何が間違っているのかわかりません。誰にも何か提案はありますか?
*注意: 私の strcmp は -1 または 1 のみを返し、0 は決して返しません
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
//Function to check if strings are a match regardless of case
bool doesMatch (char testText[], char testDeath[]) {
if (strcasecmp(testDeath, testText) == 0) {
return true;
}
else
return false;
}
int main (int argc, char *argv[]) {
char test1[5] = {getchar(), getchar(), getchar(), getchar(), getchar()};
bool testMatch;
char test2[5] = {'d','e','a','t','h'};
//Test arrays until End of FIle
while (test1[4] != EOF) {
testMatch = doesMatch(test1, test2);
if (testMatch == true) {
printf ("Match!\n");
}
//"slide" array down one character
test1[0] = test1[1];
test1[1] = test1[2];
test1[2] = test1[3];
test1[3] = test1[4];
test1[4] = getchar();
}
return 0;
}