#include <iostream>
#include <fstream>
//#include <math.h>

using namespace std;

int readFiles();
int readFile(string fileName);




ifstream in_stream;

int main()
{
    if( readFiles() < 0 )
    {
    	cout << "Terminating application" << endl;
    	exit(1);
	}
    return 0;
}

int readFiles()
{
    const int nrOfFiles = 3;
    string files[nrOfFiles] = {"AEX2006", "AEX-18jan-2006", "AEX-19jan-2006"};
    int i = 0;
    
    for(i=0; i<nrOfFiles; i++)
    {
    	if(readFile( files[i].c_str() ) < 0)
    	{
    		cout << "Critical error: cannot open file " << files[i] << endl;
            return -1;
        }
    }
    return 0;
}

int readFile(string fileName)
{
	const int maxLengthCompanyName = 100;
    char tempCompanyName[maxLengthCompanyName+1];
    string stringetje;
    float indexOrValue;

    in_stream.open( fileName.c_str() );
    if( in_stream.fail() )
    {
        return -1;
    }
       
    while( !in_stream.eof() )
    {
        in_stream.getline(tempCompanyName, maxLengthCompanyName, ':');
        in_stream >> indexOrValue;
      
        stringetje = tempCompanyName;
            
        while( in_stream.peek() == (char)13 || in_stream.peek() == '\n' )     //skip Carriage Returns (!!!) and '\n'
        {
            if( (unsigned int)in_stream.get() == 13)
            {
            	cout << "cariage return detected!" << endl;
            }
            else
            {
            	cout << "no cariage return" << endl;
            }
        }

        cout << stringetje << (char)9 << indexOrValue << endl;
	}

	cout << "--------------------------------" << endl;
	in_stream.close();
	in_stream.clear();
    return 0;
}

