Connecting Tech Pros Worldwide Forums | Help | Site Map

Data Structure and making the size change

dsa89
Guest
 
Posts: n/a
#1: Jul 22 '05
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


John Harrison
Guest
 
Posts: n/a
#2: Jul 22 '05

re: Data Structure and making the size change



"dsa89" <dsa89@vfemail.net> wrote in message
news:ff3c3d42e26d624bd31dd13a28b8abad@localhost.ta lkaboutprogramming.com...[color=blue]
>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
>[/color]

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[i]);

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


dsa89
Guest
 
Posts: n/a
#3: Jul 22 '05

re: Data Structure and making the size change


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.

John Harrison
Guest
 
Posts: n/a
#4: Jul 22 '05

re: Data Structure and making the size change



"dsa89" <dsa89@vfemail.net> wrote in message
news:5a4fdd1ec2d4b3d785b05f39c912e341@localhost.ta lkaboutprogramming.com...[color=blue]
> 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.
>[/color]

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


Closed Thread