How to add float to an array? too many initializers for 'uint8_t []

Hi everyone,

I hoped this is simple but I am missing something for sure. I figured the obvious but that doesn't work. I get this error:

too many initializers for 'uint8_t [] {aka unsigned char []}'

Here's my code:

float batteryvoltage=getRealBatteryVoltage();
static uint8_t mydata[] = {"Volts ",batteryvoltage};

Thank you

float batteryvoltage=getRealBatteryVoltage();
static uint8_t mydata[] = {"Volts ",batteryvoltage};

What index in the array would you like the battery voltage to go in?
How many items does this array hold?
How are you planning on stuffing a cString "Volts " into an array of bytes?

Arrays are lists of identical things. Ints, bytes, floats..
Arrays must be sized at compile time.


float mydata[20];         // This would set up an array of 20 floats.
mydata[12] =getRealBatteryVoltage();   // This would stuff a battery voltage into index 12 of that array.

-jim lee

float batteryvoltage;
static uint8_t mydata[] = {'V', 'o', 'l', 't', 's', ' ', 0};
//elsewhere in code
mydata[6] = batteryvoltage;

You can't declare and initialize a static variable with the return value of a function. You have to give a constant initial value for both batteryvoltage and mydata.

char mydata[25];
//elsewhere in code
snprintf(mydata, sizeof(mydata), "Volts %4.2f", getRealBatteryVoltage());