|
||
|
GP Mailing List
ATXGPSIG List
|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: pointers and text-based rpg problem
> >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...
Yeah, I thought about that so I just allocated the first dimension with 20
and left the second as 51, but it still didn't work. I see what you're
doing, and I understand how to use malloc, but I'm still a baby in the C++
language, that's part of the reason for creating this game, believe it or
not, so I have a question about one thing in your code:
What does the double indirection operator do?(when you said "char **buffer;"
and "buffer = (char **)malloc(sizeof (char*) * numfields);")
Like I said, I see that you're allocating it in Ram and that your alloating
the first dimension first, and the second dimensions second. Maybe since
you're allocating a two dimensional array, that has to do with the double
use of the indirection operator? I'm not sure, but thanks. I know that I
didn't need the & operator in front of buffer when printing it out. I was
having errors and didn't know why so I was just trying something. I forgot
it was still in my source code like that ;>). Thanks again
>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
>
_________________________________________________________________
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
|
|