forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Reading an ENTIRE file and feeding it into a buffer/string??

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
sg57



Joined: 14 Oct 2005
Posts: 154

PostPosted: Sun Mar 05, 2006 2:19 pm    Post subject: Reading an ENTIRE file and feeding it into a buffer/string?? Reply with quote

Hi

Havent posted here in a while as google has been friendly for me, until now. It has failed me.

I made some credits that work fine, ya da ya da, but I had to add some things here and there, so I made it after scrolling by everyone, read a file called 'credits' and inside there is an 'Image' made out of symbles and such, now I want to display these 'strings'/'characters' and such as they are in the file, so far I have loaded them fine, read them fine, but I cant find a call that will read more than one line of the text, I have only gotten it to flash the entire text, but only 1 char by 1 char, at the position i set it at, does anyone think they can help?

I wil however keep working on it though....
Back to top
View user's profile Send private message
framerate



Joined: 14 Aug 2005
Posts: 20

PostPosted: Sun Mar 05, 2006 2:27 pm    Post subject: Reply with quote

I might be wrong, but instead just doing something (after opening the file) like:

Code:

char* line;


Couldn't you just do a 2-d array.. something like

Code:

char** line;


or

Code:

char* line[0]; // instead of using the dual pointers...


that way you load each line (one by one) into a larger arry, and then can display the lines one by one by looping through the 2-d array?[/code]
Back to top
View user's profile Send private message
DustinFraze



Joined: 06 Jan 2006
Posts: 13

PostPosted: Sun Mar 05, 2006 2:57 pm    Post subject: Re: Reading an ENTIRE file and feeding it into a buffer/stri Reply with quote

sg57 wrote:
but I cant find a call that will read more than one line of the text, I have only gotten it to flash the entire text, but only 1 char by 1 char, at the position i set it at, does anyone think they can help?


fread()?

Or am I mis-understanding the problem?
Back to top
View user's profile Send private message
framerate



Joined: 14 Aug 2005
Posts: 20

PostPosted: Sun Mar 05, 2006 2:58 pm    Post subject: Re: Reading an ENTIRE file and feeding it into a buffer/stri Reply with quote

DustinFraze wrote:
sg57 wrote:
but I cant find a call that will read more than one line of the text, I have only gotten it to flash the entire text, but only 1 char by 1 char, at the position i set it at, does anyone think they can help?


fread()?

Or am I mis-understanding the problem?


Yeah, I wasn't 100% on what his problem was either...
Back to top
View user's profile Send private message
sg57



Joined: 14 Oct 2005
Posts: 154

PostPosted: Sun Mar 05, 2006 3:24 pm    Post subject: Reply with quote

Wow, Im an idiot (not really), I just glanced over fread(), and saw it loaded it all into a buffer, but didnt think I could print the buffer, god (smacks himself), Ill use fread(), ill post back here if I decide to have it print character x character, maybe have it do that while moving the X co-ord 10 over. But how do Istop if from disappearing?
Back to top
View user's profile Send private message
DustinFraze



Joined: 06 Jan 2006
Posts: 13

PostPosted: Sun Mar 05, 2006 3:29 pm    Post subject: Reply with quote

sg57 wrote:
But how do Istop if from disappearing?


?

The text disappears? Then what? Does the application continue to run? Do you get spit to vsh?

If the text disappears, does it then re-appear, like a flashing effect? Or does it pop up only long enough to be seen, then it's gone for good?
Back to top
View user's profile Send private message
sg57



Joined: 14 Oct 2005
Posts: 154

PostPosted: Sun Mar 05, 2006 7:50 pm    Post subject: Reply with quote

NVM about that, fread doesnt work....

here is a snippet:

Code:

    FILE *credFile;                             // FILE pointer
    credFile = fopen("data/credits", "r");     // Initialize the pointer to open credits
    long lSize;
    char * Cbuffer;

    while(1) {
                             fseek (credFile , 0 , SEEK_END);
                             lSize = ftell (credFile);
                             rewind (credFile);
                             Cbuffer = (char*) malloc (lSize);
                              fread (Cbuffer,1,lSize,credFile);             // Print the text from credit file
                            printTextScreen(5, 10, Cbuffer, RGB(255, 255, 255));
                            fclose(credFile);
                            free (Cbuffer);
}

Well? That should get the size of a file credits, then seek the last character in it, go back to start of credits file, use the malloc to find set the memory needed, then read the file with all the previous actions included/done already, then print the writing to the screen, anything worng? i get an exceptio handler
Back to top
View user's profile Send private message
Dr. Vegetable



Joined: 14 Nov 2005
Posts: 171
Location: Boston, Massachusetts

PostPosted: Sun Mar 05, 2006 8:31 pm    Post subject: Reply with quote

You are (most likely) reading the text from the file. But you need to terminate the buffer with a NUL (0x00) byte so that printTextToScreen() will know when to stop. Otherwise it will try to access memory beyond the end of Cbuffer, which will cause an exception.

Try these changes:

Cbuffer = (char*) malloc (lSize+1);
fread (Cbuffer,1,lSize,credFile);
Cbuffer[lSize] = '\0'; // NUL-terminate all C strings!

Hope this helps!
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger
sg57



Joined: 14 Oct 2005
Posts: 154

PostPosted: Mon Mar 06, 2006 8:41 am    Post subject: Reply with quote

Thanks i will. I have tried alot of different reading functions. Hope it works...
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group