我正在尝试将每个单词的单词和数量存储在一个数组中struct word
struct word{
char str[MAX_WORD_LENGTH];
int num;
}
inputFile = fopen("wordstat.txt", mode);
if(inputFile == NULL){
printf("Cannot open file\n");
return 1;
}
//scan through file to count number of possible words
while(fscanf(inputFile, "%s", scan)){
wordCount++;
}
rewind(inputFile);
struct word *words = malloc(wordCount * (sizeof *words));
如何访问字符串并将其存储到成员变量 str 中?在我做malloc之前是否需要初始化?