Jump to content

Recommended Posts

Posted

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.

Posted
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

Posted

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.

Posted

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...