wordCur 是一个大写字母的字符串,dictionary 是一个字符串数组,无论我在 wordCur 中输入什么,总是返回 0。
编辑:我稍微更新了代码,并为某些上下文添加了程序其余部分的删节版本。如此处所示,它只是在到达 checkValid 时崩溃
int main() {
FILE *ifp;
ifp = fopen("dictionary.txt", "r");
int* lDist[26];
int* lUsed[26];
int dictLen;
int i;
fscanf(ifp, "%d", &dictLen);
char dictionary[dictLen][7];
char* letters[7];
int scoreCur = 0;
int scoreHi = 0;
char wordCur[7];
char wordHi[7];
int isWord = 0;
//reads the dictionary into the array
for (i = 0; i < dictLen; i++) {
fscanf(ifp, "%s", &dictionary[i]);
}
scanf("%s", wordCur);
isWord = checkValid(wordCur, dictLen, dictionary);
if (isWord == 1) {
scoreCur = calcScore(wordCur);
}
//fclose(ifp); not sure why, but this causes a crash
return 0;
}
int checkValid (char *wordCur,int dictLen, char dictionary[dictLen]) {
int valid = 0;
int i;
for (i = 0; i < dictLen; i++){
int helper = strcmp(wordCur, dictionary[i]);
if (helper = 0){
valid = 1;
}
}