0

I want to print value in an array (array name Array_index) which I write of variable name bit_1. But when I tried to enter inside this array, the value always show zero. Please advise me how to do a correct way in Arduino.

This is my code:

int test_number = 0;
unsigned int Array_index[] = {};
int bit_1 = 0;
int Andbit = 0;
int arrSize = 0;

void setup()
{
  Serial.begin( 9600 );
}

void loop()
{
  int count = 0;
  test_number = random(10);
  Serial.println(test_number);
  for (bit_1 = 0; bit_1 <= 15; bit_1++)
  {
    Andbit = test_number & 1;

    if (Andbit == 1)
    {
      Array_index[count] = bit_1;
      //Serial.println(Array_index[count]);
      count=count++;
    }
    else
    {
    }
    test_number = test_number >> 1;
    int arrSize = sizeof(Array_index) / sizeof( int );
    Serial.println(arrSize);
    for (int y = 0; y < arrSize; y++)
    {
      Serial.println(Array_index[y]);
    }
  }
  while(1)
  {

  }

}
gre_gor
  • 6,669
  • 9
  • 47
  • 52

1 Answers1

0

unsigned int Array_index[] = {}; is an array with 0 elements.

You should define it as unsigned int Array_index[16];.

gre_gor
  • 6,669
  • 9
  • 47
  • 52