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

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...