Hello
I have a file with these contents:
7.25
8.00
10.00
11.00
12.00
15.75
25.00
40.00
85.00
125.00
How can I put them in an array of 10?
This is a discussion on filling an array with a simple file within the C Programming forums, part of the General Programming Boards category; Hello I have a file with these contents: 7.25 8.00 10.00 11.00 12.00 15.75 25.00 40.00 85.00 125.00 How can ...
Hello
I have a file with these contents:
7.25
8.00
10.00
11.00
12.00
15.75
25.00
40.00
85.00
125.00
How can I put them in an array of 10?
You want to store them in an integral array?
An array of 10 doubles, perhaps?
arya6000, you might want to read:
Lesson 8: Arrays
Rather unfortunately, it appears that the tutorial on C file I/O is not correctly linked, or non-existent. Do you know how to read from a file?
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
Use a loop to read the floating point number on each line into an element in the array.
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
Or you could use fgets to read from file and sscanf to extract the value.Code:while ( fscanf( fpointer, "%lf", &floatArray[i]) > 0 ) { printf( "%.2f\n", floatArray[i]); ++i; }