length of 2D Array >> char **myString= (char **) malloc (sizeof (char *));

Discussion in 'C++' started by davidb, Sep 1, 2006.

  1. davidb

    davidb Guest

    Hi,
    does someone know how to get the length of a 2 dimensional string
    array:
    here what i need:

    ----------------------------------------------------------------

    char **getList(void){

    char **myString= (char **) malloc (sizeof (char *));

    for(int i=0;i<10;i++){
    myString= (char **) realloc (myString, (i+1) * sizeof (char *));
    myString = (char *) malloc (255 * sizeof(char));
    strcpy (myString,"List Item");
    }
    return myString;
    }

    void something(void){
    char **dataList = getList();

    int length = ????? // IDEA ?

    for(int i=0;i<length;i++){
    printf(dataList);
    }
    }

    ----------------------------------------------------------------

    if done several experiments with sizeof like
    int length = (sizeof(array)/sizeof(array[0])
    but most time i always get length = 1.

    sorry, thats a bit simple, but i am cosseted java progger ;)
    you know > "my String".length.
    So, if you know, please tell me.

    best Regards,
    David
     
    davidb, Sep 1, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Luis

    MyString Class

    Luis, Oct 24, 2003, in forum: C++
    Replies:
    4
    Views:
    2,106
    Samuele Armondi
    Oct 24, 2003
  2. jstanforth
    Replies:
    13
    Views:
    12,910
  3. davidb
    Replies:
    6
    Views:
    1,598
    Default User
    Sep 1, 2006
  4. fuzhen
    Replies:
    8
    Views:
    550
    rahul
    Jun 12, 2008
  5. Replies:
    46
    Views:
    701
    Shao Miller
    Jan 14, 2013
Loading...

Share This Page