|
|
View previous topic :: View next topic |
Author |
Message |
cooley Guest
|
const char id[n] [*] = {"str1","str2"}; |
Posted: Sun Apr 22, 2007 8:19 pm |
|
|
when using the above as it is described in the manual. How do you access these strings?
for example printf("%s",id[1]);//does this print str1?
very confused about strings as constants and how to get them from program memory.
Thanks |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
cooley Guest
|
|
Posted: Mon Apr 23, 2007 5:05 am |
|
|
yes. I am hawke also
thanks for your help |
|
|
cooley Guest
|
|
Posted: Mon Apr 23, 2007 5:14 am |
|
|
that works for a static menu.
What I have is a large number of options and what I am looking to do is create a menu function that will display selections from a RAM buffer. upon selection by the user it will return the index of the selection to the calling function. The trick here is that the calling function will load the RAM buffer before calling the menu. The menu buffer is a RAM object and the menu strings are constants. I can't seem to get the RAM buffer properly loaded with the information from program memory in the calling program.
My goal is a single flexible menu function that I can use with any number of selections.
Any Ideas?
Thanks, |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Apr 23, 2007 5:23 am |
|
|
I'm not sure what you mean by "load the RAM buffer".
Do you mean copying an array ?
In CCS, to copy string from a 'const' array to a RAM array, you just
use their strcpy() function. See the example program below.
The program below has this output:
Code: |
#include <16F877.h>
#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
int8 const src[] = {"Hello World"};
//=======================================
void main()
{
int8 dest[20];
strcpy(dest, src);
printf(dest);
while(1);
} |
|
|
|
cooley Guest
|
|
Posted: Mon Apr 23, 2007 6:01 am |
|
|
Thats what i thought but i can't seem to make it work. is it the same for an array of strings?
ex.
const char b[3][16]={......}
main()
{
char buf[40][16];
for(i=0;i<x;i++){
strcpy(buf[i] , b[i] );
}
}
Your help is greatly appreciated |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Apr 23, 2007 12:32 pm |
|
|
Look at the demo program below. It displays the following output
when I compile it with vs. 4.032 and run it in the MPLAB simulator with
output going to 'UART1', which is then displayed in the Output window:
Quote: |
Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
|
Code: |
#include <16F877.h>
#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
char const weekday_names[7][10] =
{
{"Sunday"},
{"Monday"},
{"Tuesday"},
{"Wednesday"},
{"Thursday"},
{"Friday"},
{"Saturday"}
};
//================================
void main()
{
char ram_array[10];
int8 i;
for(i=0; i < 7; i++)
{
strcpy(ram_array, weekday_names[i]);
printf("%s\r", ram_array);
}
while(1);
} |
|
|
|
|
|
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
|