I am working on a function, which is suppose to read the size of the binary file and read the data flags. The output is suppose to look something like The dataFlags are: 1 0 1 The size of the file is: 40. I got my code running, but doesn't work like it should. I can't seem to figure out what is wrong.

Cheers.

#include <iostream>
#include <fstream>
#include <stdlib.h>

using namespace std;

int getMetaData(int dataFlags[], int &dataSize)
{

	
	ifstream binaryFile;
	
	binaryFile.open("Data.in", ios::in|ios::binary);

	
		if(!binaryFile)
		{
			cout << "The binary file data.in could not open for a binary read." << endl;
			return(1);
		}
		else if (!binaryFile.read(reinterpret_cast<char *>(dataFlags),sizeof(int)*3))
		{
			cout << "The data flags could not be read." << endl;
			return(1);
		}

		else if (!binaryFile.read(reinterpret_cast<char *>(&dataSize),sizeof(int)))
		{
			cout << "Could not read the size of the data. " << endl;
			return(1);
		}

		binaryFile.close();

		return 0;
}


int main()
{
	int getMetaData( int dataFlags[], int dataSize);

	int j;
	int& dataSize = j;
	int  dataFlags[3];
	

	cout << "The data flags are: " << endl;

	for(int i = 0; i < 3; i++)
	{
		cout << dataFlags[i] << endl;
	}
	
	cout << "The size of the data is: " << dataSize << endl;

	return(0);
}

This int getMetaData( int dataFlags[], int dataSize); is making another prototype of your function in main, and (I believe) overshadowing your prior definition of it). Go back and look over your text as to how to call a function properly (hint, you don't need the data types in the call -- you do in the function definition and prototype, though -- and there's one other change you need to make to your call)

Were that to have been a correct call, your parameters for the function are declared after you were trying to call it.

Edited 5 Years Ago by jonsca: n/a

This article has been dead for over six months. Start a new discussion instead.