< previous page page_816 next page >

Page 816
void OpenForOutput( /* inout */ ofstream& someFile )   // File to be
                                                       // opened
// Prompts the user for the name of an output file
// and attempts to open the file

// Postcondition:
//     The user has been prompted for a file name
//  && IF the file could not be opened
//         An error message has been printed
// Note:
//     Upon return from this function, the caller must test
//     the stream state to see if the file was successfully opened

{
    char fileName[51];   // User-specified file name (max. 50 chars)

    cout << Output file name: ;
    cin.get(fileName, 51);
    cin.ignore(100, \n);

    someFile.open(fileName);
    if ( !someFile )
        cout << ** Can't open  << fileName <<  ** << endl;
}

//******************************************************************
void GetRecords( /* inout */ ifstream& inFile,   // Input file
                 /* out */   PersonRec list[] )  // List receiving
                                                 //   input records
// Reads people's records from inFile
// and stores them into array list

// Precondition:
//     inFile has been successfully opened for input
//  && inFile contains at least one record and at most MAX_RECS
//     records, including the sentinel record
//  && People's last names and first names are at most
//     15 characters each
// Postcondition:
//     Assuming inFile contains N records (including the
//     sentinel record), list[0..N-1] contain the input records

{
int index = 0;   // Array index

 
< previous page page_816 next page >