Thread: Uninitialized in this function? - URGENT

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    4

    Uninitialized in this function? - URGENT

    NEVERMIND, got help. Just needed to malloc the minionsEncountered variable


    Need help with this urgent, assignment due very very soon.

    Am trying to make a function that counts all the 'minions' seen in a particular turn. I get this error
    Code:
    'minionsEncountered'  is used uninitialized in this function
    Code:
    typedef int Minion;
    Code:
    Minion *getMinionsEncountered(HunterView hv, Hunter hunter, int *numberOfMinions) {
    
       Hunter currentHunter = hv->curHunter;
       Minion* minionsEncountered;
       int turnNum = hv->turnNum;
       int currentIndex;
       int i;
       
       numberOfMinions = 0;
    
       currentIndex = 8 * currentHunter;
       for (i=0; i<turnNum; i++) {
          currentIndex = currentIndex + 40;
       }
       currentIndex = currentIndex + 3;
       
       //If its lord gamblings turn, this turn has had 0 moves so no encounters and the last move is the previous turn
       if (currentHunter == 0) {
          currentIndex = currentIndex - 40;
       }
       
       if (currentHunter == 1 && (hunter == 1 || hunter == 2 || hunter == 3)) {
          currentIndex = currentIndex - 40;
       }
       
       if (currentHunter == 2 && (hunter == 2 || hunter == 3)) {
          currentIndex = currentIndex - 40;
       }
       
       if (currentHunter == 3 && hunter == 3) {
          currentIndex = currentIndex - 40;
       }
       
       *minionsEncountered = 9;
       
       if (hv->pastPlays[currentIndex] != '.') {
          numberOfMinions ++;
          if (hv->pastPlays[currentIndex] == 'G') {
             *minionsEncountered = 0;
          } else if (hv->pastPlays[currentIndex] == 'S') {
             *minionsEncountered = 1;
          } else if (hv->pastPlays[currentIndex] == 'H') {
             *minionsEncountered = 2;
          } else if (hv->pastPlays[currentIndex] == 'M') {
             *minionsEncountered = 3;
          } else if (hv->pastPlays[currentIndex] == 'D') {
             *minionsEncountered = 4;
          } else if (hv->pastPlays[currentIndex] == 'V') {
             *minionsEncountered = 5;
          } else {
             numberOfMinions --;
          }
       }
       
       if (hv->pastPlays[currentIndex+1] != '.' && *numberOfMinions == 1) {
          numberOfMinions ++;
          currentIndex++;
          if (hv->pastPlays[currentIndex] == 'G') {
             minionsEncountered[1] = 0;
          } else if (hv->pastPlays[currentIndex] == 'S') {
             minionsEncountered[1] = 1;
          } else if (hv->pastPlays[currentIndex] == 'H') {
             minionsEncountered[1] = 2;
          } else if (hv->pastPlays[currentIndex] == 'M') {
             minionsEncountered[1] = 3;
          } else if (hv->pastPlays[currentIndex] == 'D') {
             minionsEncountered[1] = 4;
          } else if (hv->pastPlays[currentIndex] == 'V') {
             minionsEncountered[1] = 5;
          } else {
             numberOfMinions --;
          }
       }
       
       if (hv->pastPlays[currentIndex+1] != '.' && *numberOfMinions == 2) {
          numberOfMinions ++;
          currentIndex++;
          if (hv->pastPlays[currentIndex] == 'G') {
             minionsEncountered[2] = 0;
          } else if (hv->pastPlays[currentIndex] == 'S') {
             minionsEncountered[2] = 1;
          } else if (hv->pastPlays[currentIndex] == 'H') {
             minionsEncountered[2] = 2;
          } else if (hv->pastPlays[currentIndex] == 'M') {
             minionsEncountered[2] = 3;
          } else if (hv->pastPlays[currentIndex] == 'D') {
             minionsEncountered[2] = 4;
          } else if (hv->pastPlays[currentIndex] == 'V') {
             minionsEncountered[2] = 5;
          } else {
             numberOfMinions --;
          }
       }
       
       if (hv->pastPlays[currentIndex+1] != '.' && *numberOfMinions == 3) {
          numberOfMinions ++;
          currentIndex++;
          if (hv->pastPlays[currentIndex] == 'G') {
             minionsEncountered[3] = 0;
          } else if (hv->pastPlays[currentIndex] == 'S') {
             minionsEncountered[3] = 1;
          } else if (hv->pastPlays[currentIndex] == 'H') {
             minionsEncountered[3] = 2;
          } else if (hv->pastPlays[currentIndex] == 'M') {
             minionsEncountered[3] = 3;
          } else if (hv->pastPlays[currentIndex] == 'D') {
             minionsEncountered[3] = 4;
          } else if (hv->pastPlays[currentIndex] == 'V') {
             minionsEncountered[3] = 5;
          } else {
             numberOfMinions --;
          }
       }
       
       return (minionsEncountered);
       
    }
    Last edited by Natta; 09-26-2009 at 12:43 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Recursive function
    By WatchTower in forum C Programming
    Replies: 11
    Last Post: 07-15-2009, 07:42 AM
  2. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  3. dllimport function not allowed
    By steve1_rm in forum C++ Programming
    Replies: 5
    Last Post: 03-11-2008, 03:33 AM
  4. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  5. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM