using new to allocate a mult array

Started by
19 comments, last by Metal Typhoon 21 years, 3 months ago
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
Metal Typhoon
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;  


Member of the Unban Mindwipe Society (UMWS)
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
Metal Typhoon
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.

Member of the Unban Mindwipe Society (UMWS)
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*** ?
Metal Typhoon
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

Member of the Unban Mindwipe Society (UMWS)
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]
Metal Typhoon
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]
Member of the Unban Mindwipe Society (UMWS)
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) ??
Metal Typhoon
If String is defined as a char**, cin.getline(String[Loop],64) will be fine, yeah.
Member of the Unban Mindwipe Society (UMWS)

This topic is closed to new replies.

Advertisement