11-09-2005, 01:11 AM | #31 | ||
Join Date: Sep 2004
Location: Celebration, United States
Posts: 1,195
|
Then why did you promise you could do it?
|
||
|
|
11-09-2005, 10:36 AM | #32 | ||
Join Date: Dec 2004
Location: Eindhoven, Netherlands
Posts: 1,508
|
Quote:
You should look into XML! You could specify your rooms in a rather simple way: Code:
<room type="normal" id="123"> * <name>The Ultradark and dank Dungeon</name> * <exit> * * * <dir>North</dir> * * * <desc>The sturdy wooden door</desc> * </exit> * * *<exit> * * * <dir>West</dir> * * * <desc>A chain hanging from the ceiling</desc> * </exit> * <desc>The walls in this dark and dank dungeon are covered in what seem to be * * * * * * *troll excrements. Some are still warm and extremely smelly. Bit of toilet * * * * * * *paper can be seen between the goo. </desc> </room> * |
||
|
|
12-09-2005, 07:06 PM | #33 | ||
Join Date: Mar 2005
Location: Shella, Kenya
Posts: 417
|
@ Punch
I thought i could do it LOL @ Reup Wait and see i've only just got to work on the game it's self. A question for any one who can program C++ How will i save the players stats like, attack = 1, defence = 5 as fwrite and fread only accept char and strings ? |
||
|
|
12-09-2005, 08:37 PM | #34 | ||
Join Date: Jan 2005
Location: ,
Posts: 454
|
For anything.
Syntax: Code:
#include <stdio.h> *int fwrite( const void *buffer, size_t size, size_t count, FILE *stream );
__________________
Never mess with me when I have a cougar, Never! |
||
|
|
13-09-2005, 11:13 AM | #35 | ||
Join Date: Mar 2005
Location: Shella, Kenya
Posts: 417
|
hmmmm i have tryed a number of things but i still can't get it to work.
28 C:\SYS\Desktop\cpp\int-save-test\main.cpp invalid conversion from `int' to `const void*' #include <iostream> #include <fstream> using namespace std; int main() { int age = 15; int number = 22; char Fname[12]; //for filename cout<<"Enter file to save to: "; cin.getline(Fname,12); //get data cout<< endl; //Open file FILE *file; file = fopen (Fname,"w"); fwrite (age,1,sizeof(age),file); fwrite (number,2,sizeof(number),file); cin.get(); return 0; } |
||
|
|
13-09-2005, 11:38 AM | #36 | ||
Join Date: Jun 2004
Location: Jan Mayen, Svalbard and Jan Mayen
Posts: 2,167
|
uhm try &age instead of age
and &number instead of number
__________________
Flowing with the stream of life |
||
|
|
13-09-2005, 12:06 PM | #37 | ||
|
#include <iostream>
#include <fstream> using namespace std; int main() { int age = 15; int number = 22; char Fname[12]; //for filename cout<<"Enter file to save to: "; cin.getline(Fname,12); //get data cout<< endl; //Open file FILE *file; file = fopen (Fname,"w"); char buffer[2]; _itoa(age, buffer, 10); //convert int to char fwrite (buffer,sizeof(buffer), 1, file); _itoa(number, buffer, 10); fwrite (buffer,sizeof(buffer), 1, file); cin.get(); fclose(file); return 0; } It is work. |
||
|
|
15-09-2005, 08:50 AM | #38 | ||
Join Date: Mar 2005
Location: Shella, Kenya
Posts: 417
|
Well it works but I don't understand the
_itoa(number, buffer, 10); also how do I load the saved data into the correct integers? :eeeeeh: |
||
|
|
15-09-2005, 10:19 AM | #39 | ||
|
So, I don't think that it's a good idea to use "fwrite" here but if you want...
_itoa - convert an integer to a string (see MSDN). Code for save and load: Code:
#include <iostream> #include <fstream> using namespace std; int main() { int age = 15; int number = 22; char Fname[12]; //for filename cout<<"Enter file to save to: "; cin.getline(Fname,12); //get data cout<< endl; //Open file FILE *file; if ((file = fopen (Fname,"w")) != NULL) { char buffer[2]; _itoa(age, buffer, 10); //convert int to char fwrite (buffer,sizeof(char), 2, file); _itoa(number, buffer, 10); fwrite (buffer,sizeof(char), 2, file); fclose(file); } else cout<<"Error opening the file"; if ((file = fopen (Fname,"r+t")) != NULL) { char ch_age[2], ch_number[2]; fread(ch_age, sizeof(char), 2, file); fread(ch_number, sizeof(char), 2, file); fclose(file); age = atoi(ch_age); //convert char to int number = atoi(ch_number); cout<<"Age = "<<age<<" Number = "<<number; } else cout<<"Error opening the file"; cin.get(); return 0; } |
||
|
|
15-09-2005, 03:51 PM | #40 | ||
Join Date: Jun 2004
Location: Jan Mayen, Svalbard and Jan Mayen
Posts: 2,167
|
Or as you really seem to wanting to learn C++
use ifstream and ofstream class. then you can just output and load stuff like you do with cin/cout
__________________
Flowing with the stream of life |
||
|
|