Original Post
Hey all. I am reading line-by-line from a file using C++ in a console program.
Here is what I have on one line that I want to stick in variables:
1, 6 49 1 0
1,6 are the x,y coords
49 is the ASCII value of a character symbol
1 is its visible state
0 is the color
here is what I have so far to do this:
basically it works, but I haven''t figured out a better way or cleaner way to do this...anyone want to help?
And I couldn''t figure out how to get a bool value out of the visible state, seeing as how I set up my struct so that I have a variable called bool visible. So for the time being I just made it true.
inputFile.getline( buffer, BUF_SIZE );
m_nCells = atoi( buffer );
cout << "Number cells = " << m_nCells << endl;
// Get cell coords, ASCII character, visibility state
// and color for each cell
for ( int i = 0; i < m_nCells; i++ )
{
inputFile.getline( buffer, BUF_SIZE );
coordX = atoi( buffer );
int index = 0;
while ( buffer[ index ] != ''\0'' && buffer[ index ] != '','' )
{
index++;
}
if ( buffer[ index ] = '','' )
{
coordY = atoi( &buffer[ ++index ] );
}
else
{
coordY = 0;
}
cout << "x = " << coordX << " " << " y = " << coordY << endl;
Cell *ps = &cell[ coordX ][ coordY ];
ps->symbol = atoi( &buffer[ index + 2 ] );
cout << "Symbol = " << ps->symbol << endl;
ps->visible = true;
cout << "Visible = " << ps->visible << endl;
ps->color = atoi( &buffer[ index + 8 ] );
cout << "Color = " << ps->color << endl;
|