2D Array Handling in VC++
-
I need to handle a 2D Array whose first subscript is known to me only at runtime.The Array is an array of strings.The second subscript is the max size of a string.But I want to use only character arrays but not CString to represent a string. Hence,if I declare an array,like #define MAX_STRING_SZ 10 char MyArray[][MAX_STRING_SZ+1]; ... and I want to use the above array in a function F1. F1 will return such arrays , n numbers,to function F2,where The arrays's members are shown in a list view. But,the array declaration is not allowed in Microsoft Visual C++ to have empty braces[] as well as with any variable,whose value I would supply as and when I get. I am in urgent need of this. Thanking you ,The Experts,in advance!!! Best Regards, GVBhaskar srigvb@yahoo.com srigvb@rediffmail.com gvbhaskar@hotmail.com G.V.Bhaskar
-
I need to handle a 2D Array whose first subscript is known to me only at runtime.The Array is an array of strings.The second subscript is the max size of a string.But I want to use only character arrays but not CString to represent a string. Hence,if I declare an array,like #define MAX_STRING_SZ 10 char MyArray[][MAX_STRING_SZ+1]; ... and I want to use the above array in a function F1. F1 will return such arrays , n numbers,to function F2,where The arrays's members are shown in a list view. But,the array declaration is not allowed in Microsoft Visual C++ to have empty braces[] as well as with any variable,whose value I would supply as and when I get. I am in urgent need of this. Thanking you ,The Experts,in advance!!! Best Regards, GVBhaskar srigvb@yahoo.com srigvb@rediffmail.com gvbhaskar@hotmail.com G.V.Bhaskar
Can't you use CStringArray, CStringList or std::vectorstd::string ? Tomasz Sowinski -- http://www.shooltz.com
-
I need to handle a 2D Array whose first subscript is known to me only at runtime.The Array is an array of strings.The second subscript is the max size of a string.But I want to use only character arrays but not CString to represent a string. Hence,if I declare an array,like #define MAX_STRING_SZ 10 char MyArray[][MAX_STRING_SZ+1]; ... and I want to use the above array in a function F1. F1 will return such arrays , n numbers,to function F2,where The arrays's members are shown in a list view. But,the array declaration is not allowed in Microsoft Visual C++ to have empty braces[] as well as with any variable,whose value I would supply as and when I get. I am in urgent need of this. Thanking you ,The Experts,in advance!!! Best Regards, GVBhaskar srigvb@yahoo.com srigvb@rediffmail.com gvbhaskar@hotmail.com G.V.Bhaskar
First of all, I'd recommend forgetting about 2D arrays and going to something more high-level like, for instance, a
std::vector
ofstd::string
s. Anyway, if you can't afford it, the syntax you must follow is like this:void F2(char array[][MAX_STRING_SZ+1],int len);
Here
len
is needed to inform about the first dimension of the 2D array. To define a variable capable of holding 2D arrays of unspecified (i.e. determined at run-time) first dimension, the syntax is:char (* MyArray)[MAX_STRING_SZ+1];
which is also the return type of your
F1
function. Remember, the first dimension must be passed along somehow. And please allow me to recommend you again that you use STL containers to make your life easier. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo