http://GameProgrammer.Com

Programming

GP Mailing List
     Thread Index
     Date Index

ATXGPSIG List
     Thread Index
     Date Index

Google
>

Home

Wise2Food



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: pointers and text-based rpg problem



Hi, 
so far I can see a couple of mistakes...
>
>void tbox(char *text) {
>int totchars = strlen(text);
>
>int numfields =(int)(totchars/50);
>if(numfields<1){
>numfields = 1;
>}

>char buffer[numfields][51];//buffer to read text;50 +1 for null byte

Here you are allocating a buffer with a NON constant. This buffer will not
be allocated correctly...
I would do sumthing like this:
(C code)
char **buffer;
buffer = (char **)malloc(sizeof (char *) * numfields);
then do somthing like:
for(c=0;c<numfields;c++)
{
	buffer[c] = (char *)malloc(sizeof(char) * 51);
}

>int i,j;
>for(i=0;i<3;i++) {
>strncpy(buffer[i],text,50);
>}//end for...i loop
>for(j=0;j<20;j++);{
>printf("%s \n",&buffer[j]);

In correct indirection for the buffer[j].. as ur printing a string
you only need buffer[j].

Thats all I can see at the moment.
Evan,
>void main() {
>char test[] ="The Lord is my Shepherd. I shall not want. He maketh me
>to lie down in green pastures. He leadeth me beside the still waters.
>He restoreth my soul. He leadeth me in the path of righteousness for
>His names sake.";
>tbox(test);
>}
>
>         As I said, this code compiles correctly, but upon the test
>output of the text in the buffer, it prints only a little ASCII diamond.  
>Anyone's help would be greatly appreciated.
>         Also, as I am working with C++, the idea of pointers and 
>encapsulation have come to my mind and they seem to step on each other's 
>foot.  For example, if I were to create my own string class like so:
>
>class newstring{
>private:
>strdata[345];
>public:
>char *get(void);
>}
>
>wouldn't the person using this class still be able to change strdata 
>directly, without having to use some function, because of the fact that they 
>have its address?  What I'm saying is, couldn't they just write some 
>characters to that address?  I ask this because the author of my book does 
>it like that, and I'm just wondering if, instead of returning an address to 
>strdata, returning strdata by value would follow the rules of class 
>encapsulation better.  Any and all help and comments are greatly 
>appreciated. Thank you
>
>
>
>
>
>                                      Peace and may God
>                                       direct your life
>                                        Amen, Jonathan Smith
>
>_________________________________________________________________
>Get your FREE download of MSN Explorer at http://explorer.msn.com
>
>=================================================================
>The GameProgrammer.Com mailing list is for the open discussion
>of any topic related to the art, science, and business of
>programming games. This list is especially tolerant of beginners.
>We were all beginners once
>
>To SUBSCRIBE or UNSUBSCRIBE please visit:
>http://gameprogrammer.com/mailinglist.html
>
>
****
*Evan Marchant			       	
*ICQ#15055534			       					       	
*"Once one problems solved, ten are around the corner"
****
=================================================================
The GameProgrammer.Com mailing list is for the open discussion
of any topic related to the art, science, and business of
programming games. This list is especially tolerant of beginners.
We were all beginners once

To SUBSCRIBE or UNSUBSCRIBE please visit:
http://gameprogrammer.com/mailinglist.html