【发布时间】:2015-01-08 17:57:54
【问题描述】:
所以我正在从包含许多不唯一单词的文本文件中读取每个单词。我应该找到唯一单词的数量并将这些单词存储到一个名为 word 的结构变量中
我的主要问题标记在“我的问题在下面”的评论下
结构代码:
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++;
}
【问题讨论】:
标签: c struct text-files scanf