Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple question concerning arrays (C-like language)
#2
Your second while loop goes out of bounds.

b <= arraymax lets b grow to 10, and accessing array_distance[10] causes a problem.

Make your loops like this:

while (i < arraymax)

For all loops, that way you never run into indexing issues.

Code:
for(int i = 0; i < arraymax; i++)
{
    array_distance[i] = distance;
    Wait(50);
}

for(i = 0; i < arraymax; i++)
{
    NumOut(i * 4, LCD_LINE1, array_distance[i]); //printing array on LCD screen, parameters NumOut(x,y,value).
}
Reply


Messages In This Thread
Simple question concerning arrays (C-like language) - by Fiel - 2012-02-29, 01:40 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)