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?
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?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Use a loop to read the floating point number on each line into an element in the array.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
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; }