Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- VS'08 C Access Violcation When Initialising Pointer Previously had no issues
- void Mechanics::setSkillValue(int index, int value)
- {
- Skill *temp = FirstSkill; // << The error is happening on this line //
- while((temp != NULL)&&(temp->index != index))
- {
- temp = temp->next;
- }
- if (temp == NULL)
- {
- cout << "%";
- }
- else temp->setValue(value);
- // cout << temp->returnValue(); //This was a test check, not needed for anything
- }
- void Mechanics::Populate()
- {
- ifstream skillstream("Skills.txt");
- if(skillstream.is_open())
- {
- while(skillstream.good())
- {
- Skill *newskill;
- int indexval;
- string skillindex;
- string skillname;
- string skilldescription;
- cout << "TP4" << endl; //TEST POINT
- getline(skillstream, skillindex);
- cout << skillindex;
- getline(skillstream, skillname);
- cout << skillname;
- getline(skillstream, skilldescription);
- cout << skilldescription; cout << endl;
- indexval = atoi(skillindex.c_str());
- newskill = new Skill(skillname, skilldescription,indexval);
- //cout << "TP5" << endl; //TEST POINT
- if(newskill == NULL) cout << "NULL!!!";
- addSkill(newskill);
- }
- }
- ifstream itemstream("Items.txt");
- if(itemstream.is_open())
- {
- while(itemstream.good())
- {
- Item *newitem;
- int indexval;
- string skillindex;
- string skillname;
- string skilldescription;
- string abilitydescription;
- string valueSTR;
- string typeSTR;
- int value;
- int type;
- int numeric[5];
- // cout << "TP4" << endl; //TEST POINT
- getline(itemstream, skillindex);
- // cout << skillindex;
- getline(itemstream, skillname);
- // cout << skillname;
- getline(itemstream, skilldescription);
- // cout << skilldescription;
- getline(itemstream, abilitydescription);
- getline(itemstream, valueSTR);
- value = atoi(valueSTR.c_str());
- getline(itemstream,typeSTR);
- type = atoi(typeSTR.c_str());
- for (int i=0; i < 5; i++)
- {
- string numericSTR;
- getline(itemstream,numericSTR);
- numeric[i]=atoi(numericSTR.c_str());
- }
- indexval = atoi(skillindex.c_str());
- newitem = new Item(indexval, skilldescription, skillname, abilitydescription, value, type, numeric);
- //cout << "TP5" << endl; //TEST POINT
- // if(newskill == NULL) cout << "NULL!!!";
- addItem(newitem);
- }
- }
- void Mechanics::addSkill(Skill *nskill)
- {
- Skill *temp = FirstSkill;
- if(FirstSkill == NULL)
- {
- FirstSkill = nskill;
- //cout << "TP1" << endl; //TEST POINT
- //FirstSkill->printname();
- }
- else
- {
- while((temp->next != NULL))
- {
- temp = temp-> next;
- //cout << "TP2" << endl; //TEST POINT
- //temp->printname(); cout << endl;
- }
- if (FirstSkill != NULL)
- {
- temp->next = nskill;
- nskill->next = NULL;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment