View unanswered posts | View active topics It is currently Tue Oct 21, 2014 12:50 pm






Reply to topic  [ 2 posts ] 
Hardcoding an array in RobotC 
Author Message
Rookie

Joined: Fri Feb 15, 2013 12:31 pm
Posts: 1
Post Hardcoding an array in RobotC
I'm having some trouble declaring an array in RobotC.

I have a struct definition:

Code:
struct waypoint
{
   int index;
   int x;
   int y;
   int reachable_points[4];
   int counter;
   int BFSrank;
   bool visited;
} waypoint;


and when I try to initialize an array for reachable_points:

Code:
   waypoint one;
   one.index = 1;
   one.x = 9;
   one.y = 6;
   one.reachable_points = {2, -1, -1, -1};
   one.visited = false;
   one.BFSrank = -1;


The line containing the array initialization breaks, along with everything after it. If I replace the curly braces with square braces, the line remains broken, but everything after it is fine. How should I go about declaring the array?


Fri Feb 15, 2013 12:36 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3225
Location: Rotterdam, The Netherlands
Post Re: Hardcoding an array in RobotC
This works ok:
Quote:
struct waypoint
{
int index;
int x;
int y;
int *reachable_points;
int counter;
int BFSrank;
bool visited;
} waypoint;


task main()
{
waypoint one;
int foo[4] = {2, -4, -5, -1};
one.index = 1;
one.x = 9;
one.y = 6;
one.reachable_points = &foo;
one.visited = false;
one.BFSrank = -1;

writeDebugStreamLine("one.reachable_points[0]: %d", one.reachable_points[0]);
writeDebugStreamLine("one.reachable_points[1]: %d", one.reachable_points[1]);
writeDebugStreamLine("one.reachable_points[2]: %d", one.reachable_points[2]);
writeDebugStreamLine("one.reachable_points[3]: %d", one.reachable_points[3]);
}


= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Fri Feb 15, 2013 12:58 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 2 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:  



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