enum Zodiac
{
Aquarius, Pisces, Aries, Taurus,
Gemini, Cancer, Leo, Virgo,
Libra, Scorpio, Sagittarius, Capricorn
};
struct Date
{
Zodiac sign;
int day;
int month;
int year;
};
struct Info
{
char name [MAX];
char nationality [MAX];
Date birthDate;
};
so now I want to read the "Libra" from the txt file and initialize it in the Info struct (which need to be initialized in the Date struct first). As far as I know, the "Libra" value in the enum Zodiac will have a value of 8.
So my question is how do I even read the "libra" in the text file to initialize it in the Date struct?
upon more researching, would "readfile >> Info.birthdate.sign;" works?
You would have to read in the whole line (see http://www.cplusplus.com/doc/tutorial/files/), and then parse than line into separate variables (e.g. a string for the zodiac name, ints for the day month and year).
Then create your Info object.
Info myInformation;
Then assign your variables like this:
myInformation.birthdate.year = year; // where year on the rhs is your parsed int
Is this sposed to be C or C++? if you can use C++ i would use std::string's for your name and nationality.
You're going to have to make a conversion from a text string into an enum.
Something like this:
1 2 3 4 5 6 7 8 9
string temp;
Info info;
readfile >> temp;
if (bad())
// deal with error
if (temp == "Aquarius")
info.birthDate.sign = Aquarius; // Assign the enum value
... // Repeat for each of the remaining signs