File Input

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
independentCreations
Posts: 24
Joined: Fri Oct 28, 2005 10:05 am
Location: Gold Coast, QLD, Australia

File Input

Post by independentCreations »

Hey i guess its just a simple general coding problem. But i am triding to read in a .txt file. lookin something like this.

00000000000000000000
01111110111111111110
01001010100001000010
01001010111101000010
01111010100101011110
01000010100101010010
01111111111111111010
~~~~~~~~~~~~~~~~~

Where the zero's and ones stand for whether a pac man pellet will be created at its give position. i am having trouble readin it in. This is my code:

char currentChar;
for(int i = 0; i < 20; i ++)
{
for(int j = 0; j < 20; j ++)
{
fMapParam.read(reinterpret_cast<char *>(&currentChar),sizeof(char));
std::cout << currentChar;
}
std::cout << currentChar;
}
std::cout << std::endl;

It prints to the console what would seem to be weird memory addresses. Smilie faces and such thins. Any Ideas?

Thanks
"do it, do it now"
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

Are you reading and writing the file in the same way? Like maybe you're writing the file in short bytes and reading it back in long ones or the other way around.
If you're using text, why not read it in as whole lines instead of messing with individual chars
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
independentCreations
Posts: 24
Joined: Fri Oct 28, 2005 10:05 am
Location: Gold Coast, QLD, Australia

Post by independentCreations »

im not writing to the file, i just typed it up in notepad. and i have to read one charachter at a time cause each one represents a tile as such on the pacman board
"do it, do it now"
jam
Posts: 409
Joined: Fri Nov 04, 2005 3:52 am

Re: File Input

Post by jam »

as always you use my suggestions at your own risk.

but maybe this would work, not very elegant though

Code: Select all

char currentChar[1];
for(int i = 0; i < 20; i ++)
{
    for(int j = 0; j < 20; j ++)
   {
       fMapParam.read(reinterpret_cast<char *>(currentChar),sizeof(char));
       std::cout << currentChar;
    }
    std::cout << currentChar;
}
std::cout << std::endl;
Post Reply