这是我的代码。
#include <stdlib.h>
#include <stdio.h>
int main() {
    //Vars
    FILE *fp;
    char word[9999],
        *arrayOfWords[9999];
    int wordCount = 0, i;
    //Actions
    fp = fopen("data.txt", "r");
    if(fp != NULL) {
        while(!feof(fp)) {
            fscanf(fp, "%s", word);
            arrayOfWords[wordCount] = word;
            wordCount++;
        }
        for(i = 0; i < wordCount; i++) {
            printf("%s \n", arrayOfWords[i]);
        }
    puts("");
    } else {
        puts("Cannot read the file!");
    }
    return 0;
}
我正在尝试从文本文件中读取一些数据并将其存储到数组中。当我在循环中时一切都很好,但是当我离开那里时,我的数组中任何索引的任何值都被文件的最后一个单词填充。谁能帮我找出我正在做的错误?
数据文件:
Hello there, this is a new file.
结果:
file.
file.
file.
file.
file.
file.
file.
file.
任何帮助,将不胜感激!