Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   String array as parameter (http://www.velocityreviews.com/forums/t743125-string-array-as-parameter.html)

Fred 02-05-2011 03:13 PM

String array as parameter
 
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...

Ben Bacarisse 02-05-2011 03:35 PM

Re: String array as parameter
 
Fred <fred@nospam.com> 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.

Fred 02-05-2011 04:01 PM

Re: String array as parameter
 
Ben Bacarisse a écrit :
> Fred<fred@nospam.com> 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.


All times are GMT. The time now is 05:35 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.