Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 9th, 2012  |  syntax: None  |  size: 2.96 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. VS'08 C   Access Violcation When Initialising Pointer Previously had no issues
  2. void Mechanics::setSkillValue(int index, int value)
  3.    {
  4.     Skill *temp = FirstSkill; // << The error is happening on this line //
  5.  
  6.     while((temp != NULL)&&(temp->index != index))
  7.     {
  8.     temp = temp->next;
  9.     }
  10.  
  11.     if (temp == NULL)
  12.     {
  13.         cout << "%";
  14.     }
  15.     else temp->setValue(value);
  16.  
  17.  // cout << temp->returnValue(); //This was a test check, not needed for anything
  18. }
  19.        
  20. void Mechanics::Populate()
  21.  {
  22.  ifstream skillstream("Skills.txt");
  23.  if(skillstream.is_open())
  24.  {
  25.     while(skillstream.good())
  26.     {
  27.         Skill *newskill;
  28.         int indexval;
  29.         string skillindex;
  30.         string skillname;
  31.         string skilldescription;
  32.  
  33.         cout << "TP4" << endl; //TEST POINT
  34.         getline(skillstream, skillindex);
  35.         cout << skillindex;
  36.         getline(skillstream, skillname);
  37.         cout << skillname;
  38.         getline(skillstream, skilldescription);
  39.         cout << skilldescription; cout << endl;
  40.  
  41.         indexval = atoi(skillindex.c_str());
  42.  
  43.         newskill = new Skill(skillname, skilldescription,indexval);
  44.     //cout << "TP5" << endl; //TEST POINT
  45.     if(newskill == NULL) cout << "NULL!!!";
  46.     addSkill(newskill);
  47.     }
  48. }
  49.  
  50. ifstream itemstream("Items.txt");
  51. if(itemstream.is_open())
  52. {
  53.     while(itemstream.good())
  54.     {
  55.         Item *newitem;
  56.         int indexval;
  57.         string skillindex;
  58.         string skillname;
  59.         string skilldescription;
  60.         string abilitydescription;
  61.         string valueSTR;
  62.         string typeSTR;
  63.         int value;
  64.         int type;
  65.         int numeric[5];
  66. //          cout << "TP4" << endl; //TEST POINT
  67.         getline(itemstream, skillindex);
  68. //          cout << skillindex;
  69.         getline(itemstream, skillname);
  70. //      cout << skillname;
  71.         getline(itemstream, skilldescription);
  72. //      cout << skilldescription;
  73.         getline(itemstream, abilitydescription);
  74.         getline(itemstream, valueSTR);
  75.         value = atoi(valueSTR.c_str());
  76.         getline(itemstream,typeSTR);
  77.         type = atoi(typeSTR.c_str());
  78.  
  79.         for (int i=0; i < 5; i++)
  80.         {
  81.             string numericSTR;
  82.             getline(itemstream,numericSTR);
  83.             numeric[i]=atoi(numericSTR.c_str());
  84.         }
  85.  
  86.  
  87.         indexval = atoi(skillindex.c_str());
  88.  
  89.         newitem = new Item(indexval, skilldescription, skillname, abilitydescription, value, type, numeric);
  90.     //cout << "TP5" << endl; //TEST POINT
  91. //  if(newskill == NULL) cout << "NULL!!!";
  92.     addItem(newitem);
  93.     }
  94. }
  95.        
  96. void Mechanics::addSkill(Skill *nskill)
  97. {
  98.  Skill *temp = FirstSkill;
  99.  
  100.  if(FirstSkill == NULL)
  101.  {
  102.      FirstSkill = nskill;
  103.      //cout << "TP1" << endl; //TEST POINT
  104.        //FirstSkill->printname();
  105.  }
  106.  
  107.  else
  108.  {
  109.     while((temp->next != NULL))
  110.     {
  111.     temp = temp-> next;
  112.     //cout << "TP2" << endl; //TEST POINT
  113.     //temp->printname(); cout << endl;
  114.     }
  115.      if (FirstSkill != NULL)
  116.      {
  117.          temp->next = nskill;
  118.          nskill->next = NULL;
  119.      }
  120.  }
  121. }