Then I do not understand what is wrong with this:
Code:
void pickDoubleMu(teams * sPtr, matchups * head)
{
int i = 0;
char *outputText = "output.txt";
FILE *output = fopen(outputText, "w");
int randMu;
int j = 0, k;
matchups *temp;
teams *team;
teams *other;
int usedMu[20];
while(i < 20)
{
temp = head;
team = sPtr;
other = sPtr;
randMu = rand() % 45;
for(j = 0; j <= randMu; j++)
{
temp = temp->next;
}
if(temp->count == 0)
{
temp->count++;
while(temp->team1 != team->num)
{
team = team->next;
}
if(team->count < 4)
{
team->count++;
while(temp->team2 != other->num)
{
other = other->next;
}
if(other->count < 4)
{
other->count++;
}
}
}
if(team->count <= 1 && other->count <=4 && team->count <=4)
{
usedMu[i] = temp->num;
i++;
}
}
for(k = 0; k < 20; k++)
{
temp = head;
while(usedMu[k] != temp->num)
temp = temp->next;
fprintf(output, "%d\t%d\t%d\t%d\n", usedMu[k], temp->team1, temp->team2, temp->count);
}
}
It will either segfault or print duplicate values.. I want there to be no duplicates in temp->num, and each team(team->num) should be used 4 times. This will produce duplicates or infinite loop. I've been working on this program for so long and can not get it working