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

Array of Strings in CCS

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



Joined: 31 May 2004
Posts: 86
Location: Colorado Springs, CO

View user's profile Send private message

Array of Strings in CCS
PostPosted: Wed Sep 01, 2004 10:41 pm     Reply with quote

I realize CCS does not allow pointers to const data, so I can't do an array of pointers to strings in CCS (at least I haven't been able to so far), but just doing a 2 dimentional array of characters seems to be extremely inefficient. It looks like CCS is taking two bytes of ram per character to preinitialize a "char name[10][10] = (ten strings inserted here); type of array. Are there any tricks to increase efficiency and ram space for strings? It seems like you need to always copy the const string to ram before using it. I did see the "trick" of CCS being able to use a const array of chars as a parameter for a function that takes a char as a parameter and it calls it for each char in the string....
I'm guessing this is device independent and compiler independent as far as I have hear...

I have it working, but just looking to get it working with less ram or an easier way.

If you know of something, I would really appreciate knowing...

Thanks! Very Happy
Guest








PostPosted: Thu Sep 02, 2004 2:20 am     Reply with quote

In a recent project I use this:

typedef struct {
char line[16];
} dLine;

const dLine DisplayMsg[] = { // store in ROM
{"Init modem"},
{"Dialing modem"},
{"Connecting PPP"},
{"Disconnect PPP"},
{"Disconnect line"},
};

void ShowMsg(char be)
{
char j,v;

WriteDisplayData('\n'); // go to the 2nd line of LCD
for (j=0;j<16;j++) {
if (!v) break; // end of line has reached
v = DisplayMsg[be].line[j];
WriteDisplayData(v);
}
}
Guest








PostPosted: Thu Sep 02, 2004 2:22 am     Reply with quote

Copy-paste error, sorry:

for (j=0;j<16;j++) {
v = DisplayMsg[be].line[j];
if (!v) break; // end of line has reached
WriteDisplayData(v);
}
bdavis



Joined: 31 May 2004
Posts: 86
Location: Colorado Springs, CO

View user's profile Send private message

PostPosted: Thu Sep 02, 2004 8:54 am     Reply with quote

Thanks for the reply -

I changed it to:
for (i=0; i < CMD_NUM_CMDS; i++)
{
strcpy ( strTmp, CmdHandlerStr[i] );
if (strcmp( cmd, strTmp ) == 0)
{
Cmd_Execute( i, ptrArgs );

found = 1;
break;
}
}

such that CmdHandlerStr is defined as:
const char CmdHandlerStr[16][10] = { insert strings here };
and strTmp is defined as: char strTmp[16];
So I just do a strcpy() of each string from Rom/flash to Ram. Couldn't figure out why the strings in ram were taking 2 bytes per char though - that's weird to me...
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