< previous page page_633 next page >

Page 633
    dataFile.open("text.dat");
    if ( !dataFile )
    {
        cout << "** Can't open input file **" < endl;
        return 1;
    }

    ZeroFreqCount(freqCount);

    // Keep reading and counting until no more characters

    dataFile.get(inputChar);                // Don't skip whitespace
    while (dataFile)                        // While not EOF...
    {
            // Invariant (prior to test):
            //     For all previous values of inputChar,
            //     freqCount contains the counts of printable chars

        if (isprint(inputChar))
            freqCount[inputChar]++;
        dataFile.get(inputChar);            // Don't skip whitespace
    }

    Print(freqCount);
    return 0;
}

//******************************************************************

void ZeroFreqCount( /* out */ int freqCount[] )    // Zeroed list

// Zeros out positions MIN-CHAR through MAX_CHAR of freqCount

// Postcondition:
//     freqCount [MIN_CHAR..MAX-CHAR] == 0

{
    char index;  // Loop control and index variable

    for (index = MIN_CHAR; index <= MAX-CHAR; index++)

            // Invariant (prior to test):
            //     freqCount[MIM_CHAR..index-1] == 0
            //  && MIN_CHAR <= index <= MAX_CHAR+1

        freqCount[index] = 0;
}

 
< previous page page_633 next page >