CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Passing a string array to a function

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ivaneduardo747



Joined: 22 Jun 2010
Posts: 3

View user's profile Send private message

Passing a string array to a function
PostPosted: Sat Feb 05, 2011 3:36 pm     Reply with quote

How can I pass a string array like:

Code:
 const char colors[] [*] = {"Red", "Green", "Blue"};



Into a function? How the syntax would be like?
How to access it inside the function?

Also, is there any way I can get the number of elements inside an array?
Thanks!
_________________
0x2BE NOR 0X2BE
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Feb 06, 2011 2:40 pm     Reply with quote

I tested the program shown below in MPLAB simulator and got the
following output. This was tested with PCH vs. 4.118.
Quote:

Red
Green
Blue

Code:

#include <18F452.h>
#device PASS_STRINGS=IN_RAM
#fuses XT,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

const char colors[] [*] = {"Red", "Green", "Blue"};

//======================================
void main(void)
{
int8 i;

for(i = 0; i < 3; i++)
    printf("%s \r", colors[i]);


while(1);
}

I don't know how to get the number of elements from a 'const'
2-dimensional array in CCS. I don't know if it's possible.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group