View unanswered posts | View active topics It is currently Fri Oct 24, 2014 3:48 am






Reply to topic  [ 5 posts ] 
[SOLVED] 2D Array initialization 
Author Message
Rookie

Joined: Mon Jun 11, 2012 9:28 pm
Posts: 37
Post [SOLVED] 2D Array initialization
EDIT: I found an example, apparently you need a comma at the end of every row. Makes sense. Sorry.

EDIT 2: I fixed the code and it compiles correctly, and I call grid[X][Y] I do not get the value I expect. e.g. when I call grid[1][1] I expect to get '1' but I get 0, and some zeroes return ones! Any ideas regarding what I'm doing wrong?

Just a quick question - What am I doing wrong here:

Code:
const bool grid[18][7] = {
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
{0,1,0,0,0,1,1,1,0,1,1,1,1,0,1,1,1,0}
{0,1,0,0,0,1,0,0,0,1,0,0,0,0,1,0,1,0}
{0,1,0,0,0,1,1,1,0,1,0,1,1,0,1,0,1,0}
{0,1,0,0,0,1,0,0,0,1,0,0,1,0,1,0,1,0}
{0,1,1,1,0,1,1,1,0,1,1,1,1,0,1,1,1,0}
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
};


I am trying to initialize this array, but I get many errors on compile. I couldn't find any documentation on how to initialize a 2D array in robotC, so I just looked up the C way to do it.
Any advice?

Thanks!


Last edited by sqiddster on Sun Jun 17, 2012 8:28 pm, edited 3 times in total.



Sun Jun 17, 2012 12:00 pm
Profile
Expert

Joined: Tue Feb 28, 2012 3:10 pm
Posts: 195
Post Re: [UNSOLVED] 2D Array initialization
Rank and file are reversed. what you are initializing is a 7X18 array - i'm surprised it compiled, it probably should not have.

_________________
Mike aka Spiked3
http://www.spiked3.com


Sun Jun 17, 2012 3:02 pm
Profile
Rookie

Joined: Mon Jun 11, 2012 9:28 pm
Posts: 37
Post Re: [UNSOLVED] 2D Array initialization
Spiked3 wrote:
Rank and file are reversed. what you are initializing is a 7X18 array - i'm surprised it compiled, it probably should not have.


Silly me. I would have thought that the amount of elements on the X axis would be first...
Ah well, thanks.


Sun Jun 17, 2012 4:45 pm
Profile
Expert

Joined: Tue Feb 28, 2012 3:10 pm
Posts: 195
Post Re: [SOLVED] 2D Array initialization
You are creating an array of 7 objects, with 18 objects each in them. I understand the tendency to drift towards the 'XY' words, but they are more of a 2D graphics concept and not memory :) heck, I could be wrong and its just a bug. Let us know if it worked.

_________________
Mike aka Spiked3
http://www.spiked3.com


Mon Jun 18, 2012 1:02 am
Profile
Moderator
Moderator
User avatar

Joined: Thu Dec 22, 2011 7:42 am
Posts: 43
Post Re: [SOLVED] 2D Array initialization
Hi!

RobotC 3.08 has a bug when using 2D array. This bug is yet under investigations. Check this topic for more information and possible workaround (using 1D array like 2D array).

Miki.

_________________
Visit my project RainBot v0.11 on source forge, a 6 wheels robot featuring A* & Dijkstra's path finding, motors & sensors emulation, small font, fifo & sorted list libraries, using Xander's drivers for HT Compass, and documented with doxygen.


Mon Jun 18, 2012 1:24 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.