// Written by Hosung Leo Kim #include #include using namespace std; const int ARRAYSIZE( 5 ); int main() { char fileName[30]; ifstream ifs; int value; int postfixCount = 0; int valueCount = 0; int array[ ARRAYSIZE ]; cout << "File name? "; cin >> fileName; ifs.open( fileName ); if ( !ifs.is_open() ) { cout << "Opening the file for input failed. Bye" << endl; exit(1); } while( ifs >> value ) { if ( valueCount >= ARRAYSIZE ) { cout << "Error: attempted to overfill the array." << endl; postfixCount++; //COUNT THE POSTFIX while ( ifs >> value ) postfixCount++; cout << "File contains " << ( valueCount + postfixCount ) << " values." << endl; break; } array[ valueCount ] = value; valueCount++; } cout << "The values in the array: "; for ( int i = 0; i < valueCount; i++ ) cout << array[i] << " "; cout << endl; ifs.close(); return 0; } /* /homes/home30/hkim16/107a> a.out File name? lab8a.data Error: attempted to overfill the array. File contains 7 values. The values in the array: 30 50 10 80 40 /homes/home30/hkim16/107a> */