c++ - Declaring and allocating to a 2D char pointer -


how declare , allocate 2-d array without knowing beforehand how many characters per string (char array) going there? instance, this-

char** input = new char*(m*sizeof(char*)) //where m input terminal 

gives error-

error: invalid conversion ‘long unsigned int’ ‘char*’ [-fpermissive] 

building on that, have function takes char** argument. want know how many char arrays stored through pointer.

int read2darray(char* arr[]){ int l=0; while(arr[l][0]!='\0') l++; return l; } 

is correct?

that correct if being made 2d array considerate enough terminate 1d array of length 1, containing single character '\0'.

you can use convention if like. alternative pass dimensions of array additional arguments.

as declaring array, use brackets not parentheses, , don't mention sizeof(anything)-- compiler take care of sizes.

char** input = new char*[m]; 

you got error message because telling compiler create new char* value m*sizeof(char *).


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -