Objectives: This lab will help you understand arrays and
external files.
Copy and compile programs49/fig06_08.c.
Run it to observe its behavior. Now modify the program so that instead
of "hard-wiring" the data with an initializer, the program reads its
data from an external input file named histo.dat. You can use a
count-controlled loop to read SIZE
values from the file.
Reading from an input file is similar to writing to an output file, as
in Project 6. The differences are:
The fopen call uses
input instead of output mode, e.g.,
myInput = fopen ("histo.dat",
"r");
Use fscanf instead
of fprintf, e.g.,
fscanf
(myInput, "%d", &n[i]);
The data file histo.dat
is in programs49; you can
copy it and run the program, to get the same results as in the original
example. The you can modify the file with vi, to get a
different histogram.