因此,我從包含許多不是唯一單詞的文本文件中讀取每個單詞。我應該找到的唯一字的數量和那些話存入詞叫在C中插入一個單詞(char [])到一個結構詞(char [])中使用C
我的主要問題是在註釋標記的結構變量「我的問題是在這裏下面的」
結構代碼:
typedef struct {
char word[101];
int freq;
} WordArray;
代碼:
//temp[i].word is a temporary structure that scans ALL words
//input[i].word is the structure with unique words
word = fscanf(finput, "%s", &temp[i].word);
//if the word in temp[i] is in input[j].word then it is not unique
// so frequency of word is incremented
for(j = 0; j < 200; j++) {
if(strcmp(temp[i].word,input[j].word) == 0){
contains = 1;
input[j].freq++;
}
}
// MY PROBLEM IS HERE BELOW
if(contains != 1) { // since contains is not 1 then it is unique
input[i].word = temp[i].word // i want to put this word in input[i].word but this
// produces incompatible type error
// i tried strcpy and strncpy no luck...
input[i].freq++;
uniqueWords++;
}
當我用你的fscanf替換我仍然得到錯誤「錯誤:不兼容的類型時,分配到typ e'char [101]''char *'「 – geforce
'你得到那個錯誤的行,你有'temp [i] .word = something;'? –
但當我替換其他行,我有問題與「輸入[我] .word [0] =臨時[我]。字[0];「它的作品,但顯然這不會工作,當我想要存儲在這個數組中的所有單詞 – geforce