Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Metal Typhoon

using new to allocate a mult array

This topic is 5655 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i''m doing the follwing... char *Strings; then latter on the prog... Strings = new char [3][64]; but it gives me an erros saying taht i cant''t convert char (*)[64] to char *... thx alot for your help

Share this post


Link to post
Share on other sites
Advertisement

  
char** Strings;

Strings = new char*[3];
for(int i=0; i<3; i++)
Strings[i] = new char[64];


// Then to cleanup...

for(int i=0; i<3; i++)
delete[] Strings[i];
delete[] Strings;
Strings = NULL;


Share this post


Link to post
Share on other sites
question... what does the ** do ?? points to a pointer ?? or if i needed like this [3][3][64] ... it would be char ***Strings and then 2 loops to make more room ?? thx alot

Share this post


Link to post
Share on other sites
Yeah, * is a pointer, and ** is a pointer to a pointer.
If you want a 3D array, you''d need 2 loops, and char*** Strings, yeah.

Share this post


Link to post
Share on other sites
quote:
Original post by Evil Bill
Yeah, * is a pointer, and ** is a pointer to a pointer.
If you want a 3D array, you''d need 2 loops, and char*** Strings, yeah.




wowow i didnt understand this now.

i hade char *Strings;
i did the same as u said it didnt work.. but
char* Strings; worked... why is that ? any diference between char* string and char *string; ??? and what would u call this char*** ?

Share this post


Link to post
Share on other sites
It doesn''t matter where you put the *, char* Strings is the same as char *Strings and char * Strings, it must have been a bug elsewhere.
I refer to char*''s as ''strings'', so i''d call a char** an array of strings, and a char*** a 2D array of strings. Alternatively: "a pointer to a pointer to a pointer to a character". But "a 2D array of strings" is much easier

Share this post


Link to post
Share on other sites
quote:
Original post by Evil Bill
It doesn't matter where you put the *, char* Strings is the same as char *Strings and char * Strings, it must have been a bug elsewhere.
I refer to char*'s as 'strings', so i'd call a char** an array of strings, and a char*** a 2D array of strings. Alternatively: "a pointer to a pointer to a pointer to a character". But "a 2D array of strings" is much easier




ehheeh true ... hey check this out.. this is what i'm tying to do.


    
cin >> String;

for (int Room = 0; Room < String; Room++)
{Strings[Room] = new char [64];}

for (int Loop = 0; Loop < String; Loop++)
{
cout <<"String # "<<Loop<<" : ";
cin.getline (Strings[Loop][0],64);
}


is this right ??



[edited by - Metal Typhoon on December 24, 2002 9:13:58 PM]

Share this post


Link to post
Share on other sites
Room < String and Loop < String is wrong. You'll want a constant there: e.g. Room < 3.

Edit: What exactly are you trying to do? read in a number and allocate a ?x?x64 array?
If so:

  
char String[50];
int nCount;

cin >> String;
nCount = atoi(String);
Strings = new char**[nCount];
for(int i=0; i<nCount; i++)
{
Strings[i] = new char*[nCount];
for(int j=0; j<nCount; j++)
Strings[i][j] = new char[64];
}

for(int Loop=0; Loop<String; Loop++)
{
cout << "String # "<< Loop <<" : ";
cin.getline(Strings[Loop][0],64);
}

or something similar...


[edited by - Evil Bill on December 24, 2002 9:22:52 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by Evil Bill
Room < String and Loop < String is wrong. You''ll want a constant there: e.g. Room < 3.





it worked fine... cuz i''m imputeing on int String...
it''s fine.. now the other loop i dont know what''s wrong.. should i jsut do... cin.getline (String[Loop],64) ??

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!