String array as parameter

Discussion in 'C Programming' started by Fred, Feb 5, 2011.

  1. Fred

    Fred Guest

    Hello

    I have an array defined as

    char sArray[5][20] = {""};

    then I do :
    strcpy(sArray[0], "Text1");
    strcpy(sArray[1], "Text2");
    ....

    How can I pass this array to a function, to print it for example?

    I tried function(char* pArray[]) but it doesn't work...
     
    Fred, Feb 5, 2011
    #1
    1. Advertising

  2. Fred <> writes:

    > I have an array defined as
    >
    > char sArray[5][20] = {""};
    >
    > then I do :
    > strcpy(sArray[0], "Text1");
    > strcpy(sArray[1], "Text2");
    > ...
    >
    > How can I pass this array to a function, to print it for example?
    >
    > I tried function(char* pArray[]) but it doesn't work...


    Have a look at http://c-faq.com/aryptr/pass2dary.html from the
    comp.lang.c FAQ.

    You may end up with more questions than answers, but that's fine --
    any future questions you ask here will be of a more specific sort.

    --
    Ben.
     
    Ben Bacarisse, Feb 5, 2011
    #2
    1. Advertising

  3. Fred

    Fred Guest

    Ben Bacarisse a écrit :
    > Fred<> writes:
    >
    >> I have an array defined as
    >> char sArray[5][20] = {""};
    >> then I do :
    >> strcpy(sArray[0], "Text1");
    >> strcpy(sArray[1], "Text2");
    >> ...


    >> How can I pass this array to a function, to print it for example?
    >> I tried function(char* pArray[]) but it doesn't work...


    > Have a look at http://c-faq.com/aryptr/pass2dary.html from the
    > comp.lang.c FAQ.
    >
    > You may end up with more questions than answers, but that's fine --
    > any future questions you ask here will be of a more specific sort.


    Thanks, it works.
     
    Fred, Feb 5, 2011
    #3
    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. =?Utf-8?B?UmFqZXNoIHNvbmk=?=

    'System.String[]' from its string representation 'String[] Array'

    =?Utf-8?B?UmFqZXNoIHNvbmk=?=, May 4, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    1,818
    =?Utf-8?B?UmFqZXNoIHNvbmk=?=
    May 4, 2006
  2. Old Wolf
    Replies:
    0
    Views:
    569
    Old Wolf
    Mar 14, 2005
  3. Replies:
    4
    Views:
    548
    Matteo
    Mar 29, 2007
  4. Stuart Redmann
    Replies:
    5
    Views:
    527
    Stuart Redmann
    Dec 14, 2007
  5. Replies:
    5
    Views:
    661
Loading...

Share This Page