using new to allocate a mult array
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
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;
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
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.
If you want a 3D array, you''d need 2 loops, and char*** Strings, yeah.
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*** ?
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
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
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]
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:
or something similar...
[edited by - Evil Bill on December 24, 2002 9:22:52 PM]
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]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement