Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. 2D Array Handling in VC++

2D Array Handling in VC++

Scheduled Pinned Locked Moved C / C++ / MFC
c++comdata-structures
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    G V Bhaskar
    wrote on last edited by
    #1

    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

    T J 2 Replies Last reply
    0
    • G 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

      T Offline
      T Offline
      Tomasz Sowinski
      wrote on last edited by
      #2

      Can't you use CStringArray, CStringList or std::vectorstd::string ? Tomasz Sowinski -- http://www.shooltz.com

      1 Reply Last reply
      0
      • G 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

        J Offline
        J Offline
        Joaquin M Lopez Munoz
        wrote on last edited by
        #3

        First of all, I'd recommend forgetting about 2D arrays and going to something more high-level like, for instance, a std::vector of std::strings. 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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups