1. is the input file (data.txt) a binary file or a text file? If you can read it with Notepad.exe then its a text file, otherwise if the data is unreadable then its a binary file. Only binary files are read with iostream.read() function, text files use getline() or the imput operator >>.
2. wdsales() is a 2d character array. If data.txt is a binary file then you need an integer array
int wksales[rows];
infile.read ( &wksales [i], sizeof(int) )
if data.txt is a text file, then read it like this
int wksales[rows];
infile >> wksales[i];
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
The file is in Notepad so I used that code.I also change the char array to int it's not working.
Post your latest code -- we are not mind readers and I don't have my crystle ball with me today :)
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
In general, you have to read all three colums, and just igore the first 2.
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
>>char wksales[rows][columns];
you did not change this like I suggested. wksales can NOT be a 2d array of characters. The instructions say you need a 1d array of ints.
//for( i = 0; i <rows; i++)
{
int wksales[rows];
inFile >> wksales[i];
}
above is useless crap. you may as well delete it.
int wkdays[rows];
// read all the rows, ignore the first two integers
int i = 0;
int a,b,c;
while( i < rows && InFile >> a >> b >> c)
{
wkdays[i] = c;
++i;
}
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343