Thread: c++ assignment
View Single Post
 
Reply
Posted 2007-05-25, 04:01 PM in reply to Lenny's post starting "I'd be interested to see it, if only..."
here

Code:
#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
 
#define BUF_SIZE    21
#define IN_FILE        "InputData.dat"
#define OUT_FILE "OutputData.dat"
 
 
extern void main( void )
{
    ifstream    ifInputFile;
    ofstream output;
    char        sBuffer[BUF_SIZE];
    bool        bDataExists(true);
    int total;
    total = 0;
 
    ifInputFile.open("InputData.dat");
    output.open("OutputData.dat",ios::out);
 
    if( ifInputFile.is_open() != 1 )
    {
        cout << "File " << IN_FILE << " could not be opened!" << endl;
        cout << "Exiting program, good bye." << endl;
    }
    else
    {
        while( bDataExists == true )
        {
            ifInputFile.getline( sBuffer, 40 );
            if( ifInputFile.eof() == 1 )
            {
                bDataExists = false;
            }
            else
            {
                cout << sBuffer << endl;
                total=total+atoi(sBuffer);
            }
        }
        cout << total;
        ifInputFile.close();
 
        if (output.is_open() != 1)
        {
            cout << "File" << OUT_FILE << " could not be opened!" << endl;
            cout << " Exiting program.good bye" << endl;
        }
        else
        {
            output << total;
            output.close();
        }
 
    }
}

Last edited by Lenny; 2007-05-25 at 04:08 PM.
Old
Profile PM WWW Search
osmoses-jones is neither ape nor machine; has so far settled for the in-betweenosmoses-jones is neither ape nor machine; has so far settled for the in-between
 
osmoses-jones