jackchaos Posted November 7, 2006 Report Share Posted November 7, 2006 I'm at work right now and I wanted to ask about a problem I had this morning.I'm defining my pot config in structs like so.typedef struct s_pots {const unsigned char description[16];const unsigned char param1;const unsigned char type;<etc..>} pots;const pots PotConfiguration[32] {//description param1 type <etc...>{"12345678abcdefgh", 16, 2, <etc...>},{"12345678abcdefgh", 15, 2, <etc...>},};Later, the description is being passed onto MIOS_LCD_PrintCString() like so.MIOS_LCD_PrintCString(PotConfiguration[pin].description);I get an error when compiling for the 'description' const having too many elements.the error goes away if I define description with 17 elements like so:const unsigned char description[17];I'm using a 2x16 LCD screen and it seems I should define the descriptions as being 16 in length.I wipped out my old 'C' book and it looks like strings should have an additionalnull terminator. The book showed this: '\0'.Is this my problem? Do I need to make my description one extra char longer? And if I do, how do I pass a null or '\0' at the end of the string in my config above?Thanks for everything... again. Quote Link to comment Share on other sites More sharing options...
audiocommander Posted November 7, 2006 Report Share Posted November 7, 2006 I wipped out my old 'C' book and it looks like strings should have an additionalnull terminator. The book showed this: '\0'.Is this my problem? Do I need to make my description one extra char longer? I think so, yes.And if I do, how do I pass a null or '\0' at the end of the string in my config above?No, this should be done automatically for you, when you use double-quotes (").Best regards,Michael Quote Link to comment Share on other sites More sharing options...
th0mas Posted November 7, 2006 Report Share Posted November 7, 2006 Just to chime in with the post above, yeah. you need to allocate an extra byte for the null termination of the string, so 17 works but 16 won't. Quote Link to comment Share on other sites More sharing options...
jackchaos Posted November 7, 2006 Author Report Share Posted November 7, 2006 Thanks.I was worried that by declaring it [17] I was just hacking a solution... which is not what I wanted to do. Quote Link to comment Share on other sites More sharing options...
stryd_one Posted November 8, 2006 Report Share Posted November 8, 2006 This is how you know you've got too much on your mind... I just clicked reply to mention the 256 element limitation on arrays...................which we already fixed up ages ago.....and I personally documented on the wiki.... ::)OMG I'm going crazy... hahahah this is what computers will do to you!!Just a little light entertainment at my own expense :) Keeping on topic, you could always try making the string 15 chars long :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.