Leading Zeros in Array

H Guys,

I am currently attempting to program an LCD screen to control a series of lights.
As a part of this I have implemented a page for the user to select some variables or settings.

I have written an array of which the user can increment a variable and the position of the array will change.

I require to add some leading 0s to the array however it doesn't seem to accept this?

is there any way to do this?

I have no idea what you mean by "adding leading zeros to an array". What type of array? What code? Arrays always start completely full of zeros. You can make any element you want a zero. You can even use memcpy to make a bunch of them zero all at once.

I mean for example:

unsigned int example[6] = {0315,0400,0600,0630,0800,1000};

it removes the leading 0 when I try to print it to the LCD.

unsigned int example[6] = {15,400,6,630,80,1000};
Just print 0s to the LCD prior to the actual number.

if(number < 1000)
{
print 0 to the LCD
}
if(number < 100)
{
print 0 to the LCD
}
if(number < 10)
{
print 0 to the LCD
}
print number to the LCD
. . .

Numbers preceded a zero are seen as OCTAL by the compiler in much the same way as 0x is used to precede HEX numbers.

As an experiment try

Serial.println(012);  //zero, one, two

What is the output ?

it removes the leading 0 when I try to print it to the LCD

No it is the print statement that removes the leading zeros, there is no need to add them to an array it simply does not change what is in the array in the first place.

Grumpy_Mike:
No it is the print statement that removes the leading zeros, there is no need to add them to an array it simply does not change what is in the array in the first place.

Except when you write it out in your code that way, then it gets treated as octal and doesn’t have the value you thought it did.

If you look at the example in reply #2

unsigned int example[6] = {0315,0400,0600,0630,0800,1000};

Then it won't even compile because 8 is an invalid digit in an octal value