Structures problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jehudi

    #1

    Structures problem

    Hi MegaBrains,

    Working in Dev-C++ I defined the following structure

    #define NO_SECTIONS 6
    struct Track{
    int Number;
    int noElems;
    float x_pos;
    float y_pos;
    int type;
    int state;
    } ;
    Track Trk[NO_SECTIONS];

    I want to fill the Trk array with data from a data file like so:

    int trk_no, divis, i;
    float posx, posy;

    i=0;
    ifstream inifile ("init.txt") ;
    if (inifile.is_ope n())
    {
    while (! inifile.eof() )
    {
    inifile >> trk_no,divis,po sx,posy ;

    Trk.Number[i]=trk_no; <-----
    Trk.noElems[i]=divis; <-----
    Trk.x_pos[i]=posx; <-----
    Trk.y_pos[i]=posy; <-----
    i++;
    }
    inifile.close() ;
    }

    The following error typr is given for each of the lines marked above:

    request for member `Number' in `Trk', which is of non-class type
    `Track[6]'

    So what did I do wrong?
    Thanx!!
  • Tim Love

    #2
    Re: Structures problem

    Jehudi <jehudiblom@wan adoo.nl> writes:
    [color=blue]
    >Hi MegaBrains,
    > ...
    >So what did I do wrong?
    > ...
    > Trk.Number[i]=trk_no; <-----[/color]
    Try Trk[i].Number=trk_no;
    etc.

    Comment

    • Jehudi

      #3
      Re: Structures problem


      Thanks Tim,
      That was the problem!

      Tim Love wrote:
      [color=blue]
      > Jehudi <jehudiblom@wan adoo.nl> writes:
      >
      >[color=green]
      >>Hi MegaBrains,
      >>...
      >>So what did I do wrong?
      >>...
      >> Trk.Number[i]=trk_no; <-----[/color]
      >
      > Try Trk[i].Number=trk_no;
      > etc.[/color]

      Comment

      Working...