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 CCS Technical Support

const char id[n] [*] = {"str1","str2"};

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







const char id[n] [*] = {"str1","str2"};
PostPosted: Sun Apr 22, 2007 8:19 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Apr 23, 2007 12:30 am     Reply with quote

Are you the same person as Hawke ? I don't know, but the answer
to your question might be found in this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=30610
cooley
Guest







PostPosted: Mon Apr 23, 2007 5:05 am     Reply with quote

yes. I am hawke also
thanks for your help
cooley
Guest







PostPosted: Mon Apr 23, 2007 5:14 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Apr 23, 2007 5:23 am     Reply with quote

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:
Quote:

Hello World

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







PostPosted: Mon Apr 23, 2007 6:01 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Apr 23, 2007 12:32 pm     Reply with quote

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);
}
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