Reading a list of ints from file into an array
I'm having a little difficulty understanding how to read a file into an array - in this case a file of numbers (ints) into an array. I know how to open a file for reading, but once I have it open how can I read it's contents into an array? For example let's say I have the following code:
Code:
FILE* sp;
int num;
sp = fopen("rut.txt","r");
while (fscanf(sp,"%d",&num)==1)
printf("%d\n",num);
Now, lets say that the file "rut.txt" is a file full of numbers like this
124
5
-5
0
9
etc...
How can I fill an array directly from the stream? I guess I'm not understanding thee C api very well