/*==================================================================*/
/*  File:  Reopen.cpp                                               */
/*==================================================================*/
/*  This short C++ program, written for CodeWarrior/Mac,            */
/*  demonstrates how to open a file, read thru the file one line    */
/*  at a time, close the file, and then reopen it again.            */
/*  IMPORTANT:  Note the use of the  clear()  member function       */
/*  near the bottom of the for loop.  This is the "magic" that      */
/*  CodeWarrior requires in order to successfully reset itself      */
/*  so that it can successfully  open()  again.                     */
/*==================================================================*/

#include <iostream>
using namespace std; 
#include <fstream.h>
#include <stdlib.h>            // for access to exit()

int main (void)
{
    ifstream ins;              // the input stream
    char buf [100];            // a character buffer
        
    cout << "How to Reopen a file in CW/Mac" << endl;
    
    for (int i = 0; i < 3; i++)    // do this three times...
    {
        cout << endl << "Pass " << i << endl;
        
        // assume that file "SomeData.txt" is available...
        ins.open ("SomeData.txt", ios::in);
        if (! ins)            // couldn't open, so complain
        {
            cerr << "Could Not Open the File!!" << endl;
            exit (1);
        }

        while (ins.getline (buf, sizeof (buf)), ins.gcount() > 0)
        {    // read a line, echo it, again and again...
            cout << "just read: <" << buf << ">" << endl;
        }    // until you run out of data...

        ins.close ();
        
        ins.clear ();        // this is CodeWarrior MAGIC
    }
    
    return 0;
}

/*==================================================================*/

