Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

A mix up whan reading


  • Please log in to reply
1 reply to this topic

#1 Wolfy87

Wolfy87

  • Members
  • 414 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:England
  • Local time:01:38 AM

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.

BC AdBot (Login to Remove)

 


#2 Wolfy87

Wolfy87
  • Topic Starter

  • Members
  • 414 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:England
  • Local time:01:38 AM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users