Reading an ENTIRE file and feeding it into a buffer/string??
Reading an ENTIRE file and feeding it into a buffer/string??
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....
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....
I might be wrong, but instead just doing something (after opening the file) like:
Couldn't you just do a 2-d array.. something like
or
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]
Code: Select all
char* line;
Code: Select all
char** line;
Code: Select all
char* line[0]; // instead of using the dual pointers...
-
- Posts: 13
- Joined: Fri Jan 06, 2006 5:44 pm
Re: Reading an ENTIRE file and feeding it into a buffer/stri
fread()?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?
Or am I mis-understanding the problem?
Re: Reading an ENTIRE file and feeding it into a buffer/stri
Yeah, I wasn't 100% on what his problem was either...DustinFraze wrote:fread()?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?
Or am I mis-understanding the problem?
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?
-
- Posts: 13
- Joined: Fri Jan 06, 2006 5:44 pm
NVM about that, fread doesnt work....
here is a snippet:
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
here is a snippet:
Code: Select all
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);
}
-
- Posts: 171
- Joined: Mon Nov 14, 2005 1:32 am
- Location: Boston, Massachusetts
- Contact:
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!
Try these changes:
Cbuffer = (char*) malloc (lSize+1);
fread (Cbuffer,1,lSize,credFile);
Cbuffer[lSize] = '\0'; // NUL-terminate all C strings!
Hope this helps!