C - fscanf() - Reading Data Into an Array
I'm getting a strange error when reading my data into an array. My goal is to read a file that has a single column of numbers into an array, line-by-line.
#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; }
This is my compile error:
sort_algorithms.c: In function ‘main’: sort_algorithms.c:6: error: expected expression before ‘[’ token sort_algorithms.c:16: error: subscripted value is neither array nor pointer
the correct way to declare an array in c is like this:
int numArray[20];
精彩评论