Re: How to passing multidimesional array of string to function?

Discussion in 'C Programming' started by Malcolm McLean, Jul 23, 2012.

  1. בת×ריך ×™×•× ×©× ×™,23 ביולי 2012 12:53:29 UTC+1, מ×ת Alter:
    > Hi all
    >
    >
    > How to pass a multidimensional array of string to a function?
    >
    >
    >

    void multidstringfunction(char **str, int *dims, int Ndims)
    {
    int i;
    int width = 1;

    /* let's print the strings along the major dimension */
    assert(Ndims > 1);
    /* we don't know how many other dimensions there are, so we've got to
    work out the block width */
    for(i=1;i<Ndims;i++)
    width *= dims;

    /* now we can get the string at [i, 0, 0, 0 ...] by multiplying
    by width */
    for(i=0;i<dims[0];i++)
    printf("string %d - %s\n", str[i*width];
    }
     
    Malcolm McLean, Jul 23, 2012
    #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. Eric Sosman
    Replies:
    8
    Views:
    448
    Stephen Sprunk
    Jul 25, 2012
  2. Ben Bacarisse
    Replies:
    0
    Views:
    377
    Ben Bacarisse
    Jul 23, 2012
  3. Varun Tewari
    Replies:
    5
    Views:
    417
    Phil Carmody
    Jul 29, 2012
  4. aftnix
    Replies:
    0
    Views:
    352
    aftnix
    Jul 26, 2012
  5. Barry Schwarz
    Replies:
    0
    Views:
    350
    Barry Schwarz
    Jul 27, 2012
Loading...

Share This Page