Allegro - trying to read text from a file and print on screen

Started by
11 comments, last by darenking 18 years, 10 months ago
OK, anyone who's still listening...

I've just gone down the other route of reading in old C style chars.

char buffer[256];
ifstream example("filename.txt");
if(example.fail() )
{
m_Test.Input(1, "Error opening file");
}
else
{
m_Test.Input(1, "File open");
example.getline(buffer, 250);
}
example.close();

(You will note that I am using my Test object, which stores error messages etc.)

OK, that should put the first line of the text file into the char string called 'buffer', shouldn't it. But it's still not quite right as Allegro (so far as I can tell) will only output text from a pointer to an array of characters. I've tried to pass it to my method like this:

m_Test.Input(0, buffer);

But it just seems to send a blank line or something, maybe just NULL.

I've tried passing a pointer to it:

m_Test.Input(5, *buffer);

But get told off for trying to convert a char to a char!

Help!




Advertisement
Quote:Original post by joebarnslondon
I've tried passing a pointer to it:

m_Test.Input(5, *buffer);
That dereferences the pointer.

Also, try changing
void Test::Input(int line, char* input)

to
void Test::Input(int line, const char* input)

and
m_Input[line]=input;

to
strcpy(m_Input[line], input);

(Note: You'll need to include <cstring> to use strcpy).
Thanks Roboguy!

I'm finding this too complex; I think I'm going to try storing the whole thing as a C++ string object right up to the point where I have to display it on the screen. I'm sure this hasn't been a wasted conversation though. I'm a bit lost but I expect it will be useful to someone else.

I'm going to post another post about displaying string objects in Allegro (if I can't find it on google).

Thanks all!

This topic is closed to new replies.

Advertisement