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

An array of Strings

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



Joined: 14 Feb 2008
Posts: 18
Location: Cumbria

View user's profile Send private message

An array of Strings
PostPosted: Wed Nov 12, 2008 11:41 am     Reply with quote

I've gone around in circles regarding this issue, and don't understand
why the code below doesn't compile.

compiler - Version 3.249

compiler error message:

Array of bits not permitted

Any ideas?

Code:


// ------------------------------------------------------------------------
// Define string array 12 strings of length 20 characters
// ------------------------------------------------------------------------

char band_text[12][20];

// ------------------------------------------------------------------------
// Now we need to load the array with the text
// ------------------------------------------------------------------------

strcpy(&band_text[0][0],"Band = 160 Meters   ");
strcpy(&band_text[1][0],"Band = 80 Meters    ");
strcpy(&band_text[2][0],"Band = 40 Meters    ");
strcpy(&band_text[3][0],"Band = 30 Meters    ");
strcpy(&band_text[4][0],"Band = 20 Meters    ");
strcpy(&band_text[5][0],"Band = 17 Meters    ");
strcpy(&band_text[6][0],"Band = 15 Meters    ");
strcpy(&band_text[7][0],"Band = 12 Meters    ");
strcpy(&band_text[8][0],"Band = 10 Meters    ");
strcpy(&band_text[9][0],"Band = 6 Meters     ");
strcpy(&band_text[10][0],"Band = Spare 1      ");
strcpy(&band_text[11][0],"Band = Spare 2      ");



I'm planning to use this array like this:

Code:


printf(LCD_PUTC,"%s",&band_text[band_pointer][0]);



Kevin - M0KHZ
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Wed Nov 12, 2008 12:05 pm     Reply with quote

Take out the & (address of) operator and the second [0] and you get a proper address.

Code:
  strcpy(band_text[0],"Band = 160 Meters  \0");
  strcpy(band_text[1],"Band = 80 Meters   \0");
  strcpy(band_text[2],"Band = 40 Meters   \0");

note: these are NOT strings, unless you didn't leave room for the \0 string terminator!
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Thu Nov 13, 2008 3:08 am     Reply with quote

treitmey is basically correct but if you need strings of 20 char then create your array with string size of 21 to allow for the null terminating char.

char band_text[12][21];

// ------------------------------------------------------------------------
// Now we need to load the array with the text
// ------------------------------------------------------------------------

strcpy(band_text[0],"Band = 160 Meters ");

&band_text[0][0] and band_text[0] do the same thing so you should be able to use eather method.
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Thu Nov 13, 2008 8:55 am     Reply with quote

Ahh, I see. From the manual
Quote:
Copies a constant or RAM string to a RAM string. Strings are terminated with a 0.

looks like it will put in the \0 itself. Just need to have room.
M0KHZ



Joined: 14 Feb 2008
Posts: 18
Location: Cumbria

View user's profile Send private message

PostPosted: Fri Nov 14, 2008 2:07 pm     Reply with quote

Sorry for the delay in responding, but the day job has got in the way of fun!
Thanks for the answer guys. It's now working.
Kevin - M0KHZ
John P



Joined: 17 Sep 2003
Posts: 331

View user's profile Send private message

PostPosted: Fri Nov 14, 2008 3:40 pm     Reply with quote

That was an incredibly misleading error message! Array of bits, indeed.

But you could save a lot of RAM space if you used shorter strings, and did the printing as:

printf(LCD_PUTC, "BAND = %s", band_text[0]);

where each string would be loaded like this:
strcpy(band_text[0], "160 Meters ");

and so forth.
Guest








PostPosted: Fri Nov 14, 2008 4:32 pm     Reply with quote

Thanks John, this method is a whole lot smarter Very Happy
Kevin - M0KHZ
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