Hey guys, Havnt been on in a while cause ive been gaming a lot and finishing up memorizing and taking notes on my book :).
well my problem(s) right now are 1, my program has some weird numbers in it when i print the list saved in the file.
the code is :
#include <fstream.h>
#include <ctype.h>
struct TestStruct
{
char name[30];
char age[30];
};
void Add(fstream& Info);
void List(fstream& Info);
void main()
{
char ans;
fstream Info("c:\\Info.txt", ios::in | ios::end);
if (!Info)
{
cout << "****ERROR - FILE DID NOT OPEN****"<<endl;
return;
}
while(1)
{
cout << "(A)dd, (L)ist, (Q)uit? ";
cin >> ans;
switch (toupper(ans))
{
case 'A':
Add(Info);
break;
case 'L':
List(Info);
break;
case 'Q':
return;
break;
}
}
return;
}
//****************************************************************
void Add(fstream& Info)
{
TestStruct entry = {0};
cout << "Whats the persons name?? ";
cin.getline(entry.name,30);
cout <<endl;
cout << "Whats the persons age?? ";
cin.getline(entry.age,30);
Info.seekg(0L, ios::end);
Info.write((char*)&entry, sizeof(TestStruct));
}
//****************************************************************
void List(fstream& Info)
{
TestStruct entry;
int count = 0;
Info.seekg(0L,ios::beg);
while (!Info.eof())
{
Info.read((char*)&entry,sizeof(TestStruct));
if (Info.eof())
{
break;
}
cout << ++count << ": " << entry.name << '/t' << entry.age <<endl;
}
Info.clear();
}
and it gives me the numbers 12148 when i ask it to print the list, and i cant for the life of me figure out how they are being made lol.
can anyone figure this problem out??
Also, any advice on how to improve my code and stuff... mainly talking to IR or DON since you two have been helping me since i started :).
also, this code is using what my book taught me in the very last chapter, so where should i go from here, what should i look for in a c++ book to further inprove upon my knowledge :)
THANKS LOADS!!! :)
GIMPS