Reading from a file and storing it in array

Hi iam new to C programming.i have text file with 1 line containing 10 numbers each separated by blank space.i am able to store the 10 numbers in an array and use it for calculation and the program is running.what i want is if i have text file with 100 lines each having 10 numbers is it possible for me to store the numbers from each line in the same array what i used to store the numbers from line 1.so that i can use it for calculation wtihout much difficulty.any help is appreciated.i hope i made my question clear.i need the answer only in C and not in C++.

Regards
vinoth
Last edited on
Yes, you just have to know ahead of time how large to make the array (how many numbers are in the file) unless you implement a resizable array.
hi smith iam not able to understand your answer. i would appreciate if you explain it with an example.
Here is an example in the vein of what I believe you are asking.
It copies the contents of array1 into final_array, and then copies
the contents of array2 into final_array, after the elements of
the first array.

1
2
3
4
5
6
7
8
9
int array1[ 5 ] = { 1, 3, 5, 7, 9 };
int array2[ 5 ] = { 2, 4, 6, 8, 10 };
int final_array[ 10 ];

int final_index = 0;
for( int i = 0; i < 5; ++i, ++final_index )
    final_array[ final_index ] = array1[ i ];
for( int i = 0; i < 5; ++i, ++final_index )
    final_array[ final_index ] = array2[ i ];


Topic archived. No new replies allowed.