View unanswered posts | View active topics It is currently Wed Aug 27, 2014 5:17 pm






Reply to topic  [ 3 posts ] 
Arrays of Structs - Initializer error 
Author Message
Rookie

Joined: Sun Nov 16, 2008 3:07 pm
Posts: 45
Post Arrays of Structs - Initializer error
Is there a way to initialize an array of structs?

we are trying:
typedef struct
{
int iFoo;
int iBar;
} tFooBar;

tFooBar x = {1,2}; // this works OK

tFooBar y[3] ={{1,2},{3,4},{5,6}}; // this gives: **Error**:Bad initializer for variable 'y'

Related question: Is there a place in the Help etc., that discusses how RobotC varies from the C language?

Thanks.
David Fort


Thu Jan 01, 2009 8:09 pm
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: Arrays of Structs - Initializer error
I would try and declare
Code:
tFooBar x;
x.iFoo=1;
x.iBar=2;

tFooBar y[3];
y[0].iFoo=1;
y[0].iBar=2;

y[1].iFoo=3;
y[1].iBar=4;

y[2].iFoo=5;
y[2].iBar=6;



or maybe I'm wrong?

HTH!

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Fri Jan 02, 2009 2:50 pm
Profile
Expert
User avatar

Joined: Tue Oct 14, 2008 7:16 pm
Posts: 171
Location: Investigating an unidentified ship sighted in Sector 31428
Post Re: Arrays of Structs - Initializer error
Unfortunately, David, there is no such place in the very small help files regarding the diviations from C. You have to scrape the differences together from a combination of the forums, examples, and the small help files. I know, it sucks royally. It's like trying to play a game you think you know but find that the rules on this planet are different and there is no rule book.

_________________
Captain, Head programmer, School of the Arts, Silverbots Robtics Team #2890
Code:
using namespace System;
using namespace Genius;
using namespace Personality;
public ref class Nerd : Geek, IAnserable
{
    Geek::Type brainMode = Geek::Type::Programmer;
}


Wed Jan 14, 2009 5:28 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 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.