This is a continuation of program #1. This program demonstrates the use of arrays, functions, and parameters.

In this program, you will read the team data into an array, print the contents of the array before processing game data, read and process game data, and print the contents of the array after that processing. Copy your p1abc123.c to p2abc123.c so that you can modify it.

Command:

p2 -t teamFileName -g gameFileName

Input:

Team Data (same format as in program #1):

Stream input file which contains many teams. There are two different kinds of lines of data for each team:

- Team Identification Information:

o One line per team (separated by spaces)

szTeamId iWins iLosses dFeeAmount dPaidAmount
6s d d lf lf

- Team Contact Information:

o One line per team (separated by commas)

szTeamNm szEmail szPhone szContactName
12s 30s 13s 20s

o Although szTeamNm is a maximum of 12 characters, it may contain spaces; therefore, you cannot simply use %12s. For szFullName, you will have to use a bracket format code using %12[^,]. The next two values are also terminated by commas.

o For szContactName, it contains spaces and is terminated by a new line character. You will have to use a bracket format code using %20[^n]

Game Data:

Stream input file which contains many games:

o Only one type of data record (separated by spaces):

szTeamId1 szTeamId2 iScore1 iScore2
6s 6s d d

Provided files:

cs1713p2_h.txt include file for this program; rename this to cs1713p2.h
p2Team.txt input file containing team information
p2Game.txt input file containing game information
cs1713p2Provided.txt code for printTeams which you must copy into your new p2abc123.c file.

Process (see the details of the code changes later in this document):

1. Read the team information into an array using a modified getTeams function which is passed an array of teams and returns the count of the

2. Print the current team information before processing any games using the new printTeams function.

3. Print a heading showing Team 1, Team 2, Score 1, and Score 2.

4. Invoke a new processGameFile function which is passed the array of teams and the count of teams. Process the games data by reading the p2Game.txt file until EOF. For each game

  • Read a line of game data.
  • Invoke your processGame function passing that one game, the array of teams, and the count of teams.

5. Print the team array after all of the games have been processed using the printTeams function. You should notice changes in the number of losses and the number of wins.

processGame function:

  • Print the game information.
  • Lookup team 1 in the team array using your findTeam function. If not found, print a warning (e.g., team (UTSA01) not found) and return.
  • Lookup team 2 in the team array using your findTeam function. If not found, print a warning (e.g., team (XYZ001) not found) and return.
  • If the two teams are the same team, print a warning (e.g., same team) and return.
  • If the scores are the same, print a warning (e.g., game was a tie) and return.
  • Adjust the number of wins and losses for each of the teams based on which score is higher.

Error Processing:

  • There are some expected warnings (e.g., team ID not found, game was a tie) which should be printed to stdout and not cause execution to terminate.
  • Errors such as bad filename and incorrectly formatted input file should cause the program to be exited (use exitError). Note that it is unlikely this will happen for our data file.

Modifications of Program#1:

1. Above the main function:

  • change from including "cs1713p1.h" to "cs1713p2.h"
  • add this declaration: FILE *pFileGame; // stream input for games
  • change the prototype declaration for processCommandSwitches to void processCommandSwitches(int argc, char *argv[] , char **ppszTeamFileName , char **ppszGameFileName);

2. Modify the main function as necessary:

  • Declare Team teamM[MAX_TEAMS];
  • Declare a variable for the count of the number of entries in the teamM array.
  • Declare a variable for the game file name: char *pszGameFileName = NULL;
  • Just like the code for opening the Team file, add code to check the Game file name and open the Game file.
  • Change the call to getTeams to pass the teamM array and assign the function results into your variable for the count of teams.
  • Print the original contents of the team array before processing the game data by calling printTeams passing the team array and the count of teams.
  • Invoke processGameFile, passing the teamM array and the count of the number of entries in that array
  • Print the resulting contents of the team array using the printTeams function.

3. processCommandSwitches needs to be modified to return multiple filenames (one for the team file and one for the game file). (See the prototype declaration above.)

4. Modify getTeams to receive the array of teams and return the number of teams.

  • Change your documentation to include:
Parameters:
O Team teamM[] array of teams
Returns:
Count of the number of teams
  • Since you already have code to read the data into a simple structure named team, simply copy it into the array:
teamM[i] = team; // You also need to declare i at the beginning of this function
  • Return the count of teams as its functional value.
  • The prototype for getTeams is now: int getTeams(Team teamM[])

5. Add a new function processGameFile which is passed an array of teams and team count as parameters. It should read data from the game file until EOF. For each game read, it should invoke processGame passing the game, array of teams, and team count. Its prototype is void processGameFile(Team teamM[], int iTeamCnt)

6. Add a new function processGame which processes a game as described above. It is passed a game, the array of teams, and the team count. Its prototype is void processGame(Game game, Team teamM[], int iTeamCnt)

7. Add a new function findTeam which finds the specified Team Id in the teamM array and returns its subscript. If not found, it should return -1. int findTeam(Team teamM[], int iTeamCount, char szTeamId[])

8. exitUsage should show what switches it now needs.

9. Copy the text from cs1713p2Provided.txt into your p2abc123.c file. See how to do that below.

Sample Output (Partial):

Original Team Information
Id Team Name Wins Loss Fee Amt Paid Amt
Contact Name Phone Email
UTSA01 Armadillos 8 0 150.00 80.00
Jean E Us (210)555-1111 utsa@xyz.com
COM001 Comm Eagles 7 1 150.00 75.00
Mae King (210)555-2222 maeking@xyz.com
SOUTH1 Slam Dunk 5 3 120.00 75.00
Jerry Tall (210)555-3333 slamdunk@gmail.com
ALHGHT Cake Eaters 4 4 175.00 100.00
E Z Street (210)555-6666 sliverspoon@xyz.com
UNKN01 Org New Blk 1 7 150.00 50.00
Bob Wire (210)555-1234 bobwire@xyz.com
NEWB01 River Rats 0 8 120.00 75.00
Rock D Boat (210)555-4444 riverrat@xyz.com
UNKN02 Hackers 3 5 150.00 75.00
Tom E Gunn (210)555-5555 cyber@gmail.com
Processing Games
UTSA01 NEWB01 55 12
COMM01 SOUTH1 17 15 *** team (COMM01) not found
SOUTH1 ALHGHT 66 3
UTSA01 SOUTH1 44 45
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.