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);
}