C - fscanf() - 将数据读入数组

nic*_*ame -2 c arrays scanf

将数据读入数组时遇到奇怪的错误.我的目标是逐行读取具有单列数字的文件到一个数组中.

#include <stdio.h>

int main() {
    int numArray = [20];
    int i = 0;

    FILE *infile;
    infile = fopen("numbers", "r");

    while(!feof(infile))
    {
        fscanf(infile,"%d",&numArray[i]);
        i++;
    }

    fclose(infile);
    return 0; }
Run Code Online (Sandbox Code Playgroud)

这是我的编译错误:

sort_algorithms.c:在函数'main'中:sort_algorithms.c:6:错误:在'['标记sort_algorithms.c:16之前的预期表达式:错误:下标值既不是数组也不是指针

mpo*_*z08 7

在c中声明数组的正确方法是这样的:

int numArray[20];
Run Code Online (Sandbox Code Playgroud)