I've been trying to do this for two days solid now (seriously) and whilst I know it's easy to some people, I'm finding it hard to figure out as I've never done it before, and whenever I ask people for help they either say something I don't understand, or go wayy over my head saying use vectors, or overload this and that.
If anyone could PLEASE just help me out with reading from the txt file so that the first food item goes into the first struct I would be EXTREMLY grateful. I appreciate just giving someone the answers isn't helpful, but being stuck with one issue for this long is not helpful either. I know my code may not be 'optimised', or have other issues I'm not aware of, but that's because I'm new to all this and trying to teach myself.
Sorry for the long post, but I've become really frustrated with this, because I know that once I do have a working program, I'll be able to go through it slowly with the debugger step by step, and that way I'll get it into my head, it's just the way my brain works.
Many many thanks to anyone who can help me with this.
Swerve
P.S. I've attached a screen shot of the txt file, because I don't understand how it knows which bit to read.
Last edited by Swerve; March 17th, 2008 at 09:03 PM.
I've been trying to do this for two days solid now (seriously) and whilst I know it's easy to some people, I'm finding it hard to figure out as I've never done it before,
And you found no books, nothing, on this very basic concept??
P.S. I've attached a screen shot of the txt file, because I don't understand how it knows which bit to read.
If you had to read in from the keyboard, it is no different than if you read one line of the file.
But I'm wanting to enter all the items from the txt file into an ARRAY of STRUCTS.
You write a loop, just like you did when you were saving the data.
I think your problem has less to do with reading into an array of struct, and more into what an array of struct is and how to manipulate one, regardless of whether you're reading or not.
Do you know how to declare an array of structs? If so, do you know how to access, say the third element of this array, and say, a member called "name"?
Code:
struct foo
{
char name[30];
int age;
};
int main()
{
foo myNames[10]; // an array of 10 foo;s
}
Similarly, what does this loop do?
Code:
for (int i = 0; i < 10; ++i)
{
foo[i].age = 20;
}
So if you know the answers to this, then I don't see why the file read is such a problem.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.