/*
    Array2.java
    CIS 111
    David Klick
    11/05/07

    Reading array elements from a file; also demonstrates
    how to use partially filled arrays.
*/

public class Array2 extends CIS111App {
    public static void main(String[] args) {
        String[] names = new String[100];
        SequentialFile filein = new SequentialFile("peoplej.txt", FileMode.INPUT);
        int numNames = 0;

        // read names from file and place in array
        while (!filein.eof() && numNames<names.length) {
            names[numNames] = filein.readString();
            numNames++;
        }
      
        // check for array overflow
        if (!filein.eof()) {
            println("Error: Too many records in file");
        }
      
        // close file
        filein.close();
      
        // display what is in array
        for (int i=0; i<numNames; i++) {
            printf("%3d: %20s\n", (i+1), names[i]);
        }
    }
}