Good Evening everyone, long time lurker, first time poster. I have an issue trying to read information from a file that I'm struggling with. My function takes a file input object and reads information into arrays of type int, int, double, char (2 dimensional array). The file data looks like this:

512 43 10.19 chips

// global constant
const int MAX = 30;

//function header
void printStats( int a[], int b[], double c[], char d[][MAX], ostream&, ifstream& );

//function body
void printStats( int a[], int b[], double c[], char d[][MAX], ostream& dataOut, ifstream& fileIn )	{
	int count = 0;
	while ( !fileIn.eof() )	{
		fileIn >> a[count] >> b[count] >> c[count] >> d[count];
		count++;
	}
}

At this point, this function simply doesn't work and I don't think I'm understanding the 2-D array correctly. I tried using:

while ( !fileIn.eof() )	{
		fileIn >> a[count] >> b[count] >> c[count];
		fileIn.getline( d[count], MAX, '\n' );
		count++;
	}

but my character array ends up collecting the first integer on the newline...I was under the impression that as long as I passed a 2-D array a size for the number of columns, I could simply read data into it by passing d[count]......

I left the majority of my code out of this post to keep things simple, so I hope I've given a clear idea of the situation.

Try passing "a 2-D array a size for the number of" rows, not columns

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.