我正在编写一个应该从命令输入的程序,然后找到输入的词频。我在使用 strcmp() 函数比较字符串(字符数组)时遇到问题。我已经做了几个小时,但我仍然不明白我做错了什么。跟指针有关系吗?这是我的代码:
#include <stdio.h>
#include <string.h>
int main(){
char Words[501][21];
int FreqNumbers[500];
char temp[21] = "zzzzz";
char Frequency[5][21];
int wordCount = 0;
int numberCount = 0;
int i = 0;
int counter = 0;
int end = 0;
do {
scanf("%20s",Words[wordCount]);
for(counter = 0;counter < wordCount;counter++){
if(wordCount > 0){
if(strcmp(Words[wordCount], Words[counter]) == 0){
FreqNumbers[counter]++;
break;
}
FreqNumbers[wordCount]++;
}
}
wordCount++;
printf("%s", Words[wordCount - 1]);
printf("%s", temp);
} while(strcmp(Words[wordCount],&temp) != 0);
return(0);
}