Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > String array as parameter

Reply
Thread Tools

String array as parameter

 
 
Fred
Guest
Posts: n/a
 
      02-05-2011
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...
 
Reply With Quote
 
 
 
 
Ben Bacarisse
Guest
Posts: n/a
 
      02-05-2011
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.
 
Reply With Quote
 
 
 
 
Fred
Guest
Posts: n/a
 
      02-05-2011
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using declaration inside first template parameter as default valuefor second template parameter. Stuart Redmann C++ 5 12-14-2007 08:42 AM
Parameter List / Parameter Block / Anything patterns... mast2as@yahoo.com C++ 4 03-29-2007 09:37 PM
'System.String[]' from its string representation 'String[] Array' =?Utf-8?B?UmFqZXNoIHNvbmk=?= ASP .Net 0 05-04-2006 04:29 PM
string literal does not match array template parameter Old Wolf C++ 0 03-14-2005 08:48 PM
string literal as const string& parameter selder21@hotmail.com C++ 5 09-22-2003 11:50 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57