jeudi 23 janvier 2020

taking values from an rtf or a txt file

course menu has a vector of courses and each course has an id, a name, no of credits, description and a set of prerequisites

void AUC::load_catalog(course_menu & cm, course c){

    char yn;
    cout<<"do you want to load the saved catalog?   (y/n)";
    cin>>yn;
    if ((yn='Y')||(yn='y'))
        {
        ifstream infile;
        infile.open("cata.rtf");

file always fails to load properly

        if(infile.fail())
            {cerr<<"error opening file"<<endl;exit(1);}
        char* id;
        char* name;
        char* ch;
        char* description;
        char* prereqs;

looping through the file to get all the course details and put them in the correct element in the class

        while (!infile.eof()){
        infile>> id>>name>>ch>>description>>prereqs;
            char* ID=  strtok(id, ":");
            c.set_courseID(ID);

            char* Name= strtok(name, ":");
            c.set_course_name(Name);

            char* CH= strtok(ch,":");
            int credits= atoi(CH);
            c.set_credit_hours(credits);

            char* Desc= strtok(description, ":");
            c.set_course_description(Desc);

            char* Pre= strtok(prereqs, ":");
            if (Pre==(char*)" ") c.set_prerequisits(" ");
            else c.set_prerequisits(Pre);
            return;
        }
    }else return;
}

Aucun commentaire:

Enregistrer un commentaire