![]() |
|
Simple question concerning arrays (C-like language) - Printable Version +- Southperry.net (https://www.southperry.net) +-- Forum: Social (https://www.southperry.net/forumdisplay.php?fid=14) +--- Forum: Rubik's Cube (https://www.southperry.net/forumdisplay.php?fid=58) +--- Thread: Simple question concerning arrays (C-like language) (/showthread.php?tid=52122) |
Simple question concerning arrays (C-like language) - prozard - 2012-02-29 My problem is probably too simple for words, but I can't figure out what I am doing wrong. I am currently programming in NXC (Not Exactly C) for a LEGO mindstorm robot, and my code is supposed to have the robot decide autonomously wether or not it is standing upright. This by means of comparing sensor values stored in an array. Sadly, it hasn't even come close to that point, with errors all over the place and now a runtime error ('file error' when running the program, probably caused by indexing values in nonexistant arrays - that's what googling told me). My code:
Spoiler
Help me please. Help will be appreciated. Simple question concerning arrays (C-like language) - Fiel - 2012-02-29 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++)Simple question concerning arrays (C-like language) - prozard - 2012-02-29 Thanks, that certainly helped me out. As I said, too simple for words. Now to figure out why my sensor isn't providing the values I'd expect it to give, could it perhaps be that the ArrayInit overrules my loop? |