ivaneduardo747
Joined: 22 Jun 2010 Posts: 3
|
Passing a string array to a function |
Posted: Sat Feb 05, 2011 3:36 pm |
|
|
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
|
|
Posted: Sun Feb 06, 2011 2:40 pm |
|
|
I tested the program shown below in MPLAB simulator and got the
following output. This was tested with PCH vs. 4.118.
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. |
|