Arrays and Pointers

closed account (oE6pX9L8)
They're both lovely things, and I can see their use, but why do they have to be so damn hard to remember? How many ways can you use a pointer, anyway?

I've pretty much covered everything in the tutorial on them, and I'm about to move onto dynamic memory. I need to be able to import a text file of an undetermined amount of lines. I've already checked the file handling library, and it's been a while, but I think I'll be able to manage it. If someone could explain the best way of importing data in files, say for example, a file like this:

1;Sword;70;85;A basic blade used for fighting.
2;Axe;75;75;A stronger blade that's harder to wield.
3;Lance;60;95;A light wooden spear, effective at accuracy.


That would be really helpful. Or even just how to move the importing cursor, and such. I don't really understand it :(

I'm thinking of making a game, and I'd want to use Access to export a text file with the data, then import it with the .exe.

Thanks.

archmage84
If you're using C++, you can use fstream to read line by line (use getline()) and store the information separated by semicolons.
You would need a sort of 'list' with undetermined size. Arrays hold a determined number of elements. If you are familiar with the C++ standard library, you might want to use something like a vector, if you aren't familiar with that you probably need to reed on to dynamic memory, with dynamic memory you can create 'arrays' with undetermined size. You can create 4 or 5 of those 'list', but you can also create one list with a struct of those 4/5 informations of the text file, if you are familiar with structs.

PS: With undetermined size, I mean size that you figure from the file, which is not known at the moment of writing the app.
Topic archived. No new replies allowed.