//----------------------------------------------------------------------
//  filepos.cpp
//  This program prompts the user for a file name, then prompts for the
//  position (0, 1, 2, ...) of any character in the file.  It then
//  displays the character found at that position and prompts the user
//  for another position.  This continues until the user types a
//  negative number for the position.  If the specified position is
//  greater than the size of the file, the results are undefined.
//----------------------------------------------------------------------
#include <iostream.h>
#include <fstream.h>

int main()
{
    char      fName[20];
    streampos position;
    char      ch;

    cout << "File name: ";
    cin >> fName;

    ifstream inFile(fName);
    if ( !inFile ) {
        cout << "Can't open file\n";
        return 1;
    }

    do {
        cout << "Char at which position (0, 1, 2, ...) ? ";
        cin >> position;
        if (position >= 0) {
            inFile.seekg(position);
            inFile.get(ch);
            cout << "Char: " << ch << '\n';
        }
    } while (position >= 0);

    return 0;
}


