lundi 9 mai 2016

Randomly Pair Teams From Text File Twice

I'm fairly new to C programming and I'm attempting to complete this random pairing program but I'm having issues with starting it. Basically, the program needs to read in the 3 letter team names from a text file, place them into an array, and then randomly pair teams against each other. There are two rounds and in the second round, there cannot be any rematches. Additionally, teams from the same school cannot play against each other. Teams from the same school share the same first character and line in the text file. Can anyone help me with how to code this? :) Here is the text file named provisions.txt:

ABA ABC ABD ABG

BAA BAB BAC

CAB CBA

DAB DBC DBE DBA

EAB

FAB FAC FAA

GAB GAA

HAA HAB

IAB

JAA

KAA

LAL LAB

MAA MAB MBA MUM

NAN NAB

My code so far is:

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <math.h>

int main()
{
// Read characters from text file into array

FILE *file = fopen("provision.txt", "r");

char teams[115];

while(fscanf(file, "%s", teams) != EOF){
    printf("%s ", teams); }   // Print to make sure the file is read

// Clean up
fclose(file);

return 0;
}

If possible, I would like to store the output of both rounds in text files named round1_pairings.txt and round2_pairings.txt.




Aucun commentaire:

Enregistrer un commentaire