item database in .txt solutions

hello everyone! I am a beginner in programming. I am making an RPG game that mostly resemble ragnarok but text based.
my problem is on item database. i need something like a function in main/class(i don't really know) that determine the item and implement it to the character only by the id number of a specific item that is read from a text document. i already have played around with file handling and was successful. could you please help me? it's not a project or anything but it is really important to me. thanks for the reply.^_^
Last edited on
Look into the <fstream> library.

and here:

http://www.cplusplus.com/doc/tutorial/files/
thanks! i used fstream on reading the fie but used stdio(fopen, etc.) in writing the file. i got lazy on that one.

what method do i use to determine an item only by the id number of the specific item? any ideas?
Well lets say the item database looked like this:

1234560 Sword 15

you would have to do something like this, first declare an array for item ids, item names, and whatever else. It would be a good idea to have seperate arrays for weapons and items. (im not to specific here):

const int NUM_ITEMS = (NUMBER OF TOTAL ITEMS HERE)

1
2
3
4
5
int i = 0;
ifstream inFile;

for (i = 0, i < NUM_ITEMS; i++)
     inFile >> id_num[i] >> weapon_name[i] >> weapon_str[i]


That would take care of assigning ids and all that to an array.

If I thought about it more I could help you out but I'm extremely sleepy, just trying to point you in the right direction.

and have it do that until it reaches end of file
Last edited on
thanks again! I'm gonna look at it in further detail later. research thoroughly for forums that might have covered id_numbers with file handling. and pray for some idea that will go into my head. thanks again!

ragnarok has an item_db text document that contains like this:

ID_NO, NAME, WEIGHT, BUY, SELL, STR, AGI, etc..
10001, knife, 30, 100, 50, 0, 0,...
10002, axe, 50, 220, 110, 0, 0,...

mine was:

10001 knife 30 100 50 0 0
10002 axe 50 220 110 0 0

i managed to read the data and neglect the space.

i want to recreate this item database by saving the values read from the .txt to variables on my program. when ID_NO is called(like equipping it/etc..), it will load the the rest of the info into the program just by the ID_NO itself. any ideas where the process of identifying the item through ID_NO be? i partially thought about putting it into the character class, main , other functions. but still not clear on the idea.


thanks for the reply! your help is always welcome and appreciated. ^_^
Topic archived. No new replies allowed.