Data Structure and making the size change

Discussion in 'C++' started by dsa89, Nov 7, 2004.

  1. dsa89

    dsa89 Guest

    I would like to know if anyone can help me with this. I would like to load
    a file into a data structure but dont know how. Here is an example file.

    ;File Example
    ;Created 03/04/99
    [Command]
    name = "2QCF_y"
    command = ~D, DF, F, D, DF, F, y

    [Command]
    name = "5b"
    command = b, b, b, b, b
    time = 30
    etc....

    My question is if someone can help me to load any file (I know how to
    open it) but then input it into a data structure where each case is

    command = ......

    My problem is making the data structure increase or decrease depending on
    the number of commands. Can anyone help me with this by pointing me in the
    right direction A little code would be nice but an explanation is just as
    good. Thanks
     
    dsa89, Nov 7, 2004
    #1
    1. Advertising

  2. "dsa89" <> wrote in message
    news:...
    >I would like to know if anyone can help me with this. I would like to load
    > a file into a data structure but dont know how. Here is an example file.
    >
    > ;File Example
    > ;Created 03/04/99
    > [Command]
    > name = "2QCF_y"
    > command = ~D, DF, F, D, DF, F, y
    >
    > [Command]
    > name = "5b"
    > command = b, b, b, b, b
    > time = 30
    > etc....
    >
    > My question is if someone can help me to load any file (I know how to
    > open it) but then input it into a data structure where each case is
    >
    > command = ......
    >
    > My problem is making the data structure increase or decrease depending on
    > the number of commands. Can anyone help me with this by pointing me in the
    > right direction A little code would be nice but an explanation is just as
    > good. Thanks
    >


    C++ has lots of data structures built in. One of the simplest to use is
    called a vector. Here's a little sample

    #include <vector>
    #include <string>

    struct Command
    {
    std::string name;
    std::string command;
    int time;
    };

    // here's your vector of commands
    std::vector<Command> command_vector;

    // here's how to add a command to the command vector
    Command a_command;
    command_vector.push_back(a_command);

    // here's how to loop though all the commands
    for (int i = 0; i < command_vector.size(); ++i)
    print_command(command_vector);

    etc. etc.

    Any decent C++ book will talk about the vector class and a whole lot more.
    Perhaps you need to invest in one?

    john
     
    John Harrison, Nov 7, 2004
    #2
    1. Advertising

  3. dsa89

    dsa89 Guest

    Just in a little hurry and am coding in c++ for the first time. Yes, I will
    invest in one.

    So that code will work for what I am looking for, or would I need to
    expand it? Add something or other?

    Thanks.
     
    dsa89, Nov 7, 2004
    #3
  4. "dsa89" <> wrote in message
    news:...
    > Just in a little hurry and am coding in c++ for the first time. Yes, I
    > will
    > invest in one.
    >
    > So that code will work for what I am looking for, or would I need to
    > expand it? Add something or other?
    >
    > Thanks.
    >


    You will need to expand it A LOT.

    Are you an experienced programmer (even if not in C++). You seem to have
    given yourself quite a difficult and tedious project for a first attempt at
    C++.

    Are you sure that C++ is the most suitable language. Nothing in C++ makes it
    especially suitable for what you have described so far. I would choose to do
    this in C++ but only because I'm very familiar with the language, if you are
    more familiar with a different language it might be better to stick with
    that.

    If you have programmed other languages before then 'Accelerated C++' by
    Koenig and Moo might be suitable, but no-one learns C++ in a hurry.

    john
     
    John Harrison, Nov 8, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Wongod
    Replies:
    2
    Views:
    714
  2. Kislay

    Size of a structure : Structure Padding

    Kislay, Oct 1, 2007, in forum: C Programming
    Replies:
    15
    Views:
    959
    clinuxpro
    Jul 13, 2011
  3. Jason Cavett

    Preferred Size, Minimum Size, Size

    Jason Cavett, May 23, 2008, in forum: Java
    Replies:
    5
    Views:
    12,583
    Michael Jung
    May 25, 2008
  4. A
    Replies:
    27
    Views:
    1,602
    Jorgen Grahn
    Apr 17, 2011
  5. tom c
    Replies:
    1
    Views:
    204
    PeterKellner
    Jun 8, 2006
Loading...

Share This Page