BleepingComputer.com: A mix up whan reading

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

A mix up whan reading Written in C++/SDL

#1 User is offline   Wolfy87 

  • Senior Member
  • PipPipPipPip
  • Find Topics
  • Group: Members
  • Posts: 414
  • Joined: 25-July 08
  • Gender:Male
  • Location:England

Posted 06 February 2010 - 11:14 AM

Hi, I am making a very simple program that reads a data file and displays the contents in the form of tiles.

For some reason the top line of tiles gets completely messed up somewhere but the rest is file.

I have zipped up the whole project and it is compiled for Windows and Linux. You can download it here.

The main areas that could effect this are:

int displayData()
{
	for(int y = 0; y < 6; y++)
	{
		for(int x = 0; x < 6; x++)
		{
			switch(data[x][y])
			{
				case 0:
					boxRGBA(screen, x * 50, y * 50, x * 50 + 50, y * 50 + 50, 0, 255, 0, 255);
					break;
				case 1:
					boxRGBA(screen, x * 50, y * 50, x * 50 + 50, y * 50 + 50, 0, 0, 255, 255);
					break;
				case 2:
					boxRGBA(screen, x * 50, y * 50, x * 50 + 50, y * 50 + 50, 0, 0, 0, 255);
					break;
				case 3:
					boxRGBA(screen, x * 50, y * 50, x * 50 + 50, y * 50 + 50, 200, 200, 200, 255);
					break;
				case 4:
					boxRGBA(screen, x * 50, y * 50, x * 50 + 50, y * 50 + 50, 255, 0, 255, 255);
					break;
				case 5:
					boxRGBA(screen, x * 50, y * 50, x * 50 + 50, y * 50 + 50, 255, 0, 0, 255);
					break;
				default:
					boxRGBA(screen, x * 50, y * 50, x * 50 + 50, y * 50 + 50, 255, 255, 255, 255);
					break;
			}
		}
	}
	
	return 0;
}


// Open the file
	file.open("./data.dat");
	
	// Read the file into the data array
	for(int y = 0; y < 6; y++)
	{
		for(int x = 0; x < 6; x++)
		{
			file >> data[x][y];
		}
	}
	
	// Display the data
	displayData();
		...


Any help will be great, thanks, Wolfy87.

#2 User is offline   Wolfy87 

  • Senior Member
  • PipPipPipPip
  • Find Topics
  • Group: Members
  • Posts: 414
  • Joined: 25-July 08
  • Gender:Male
  • Location:England

Posted 06 February 2010 - 05:41 PM

Ok the displaying works fine, I have figured out that it fails when reading the first 6 characters of the data file, but the rest works fine.

I have no idea why it only does it for the first line.

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users