For this assignment you will be combining file IO, dynamic memory allocation, and structures
by processing a NFL team roster. Football I usually big among the population, so I picked a
football roster for the input file with standardized data. Additionally, football rosters are large
enough so your solution will be not trivial.
Part 1: Count the number of players
I have attached the 2015 Kansas City Chiefs in CSV format. Many datasets out there are in CSV
format. CSV stands for comma separated values. The basic format of each object of the dataset is
a line in the datafile, and each field of that element is separated by a comma, hence the name.
For this part, I want you to count the number of players on the roster.
You will use this number to dynamically allocate memory in the next part so it's important you
get the number correct.
As a test, there are 90 players on the roster, so if you get more or less than that don't move to part
2.
Part 2: Read the players into a data structure
Now that you know how many players there are on the roster, you will now need to read the
players from the roster into your array.
Before you do that you will need to create a data structure to hold the data.
Each player has specific attributes associated with them and each has a type that should be used
with that attribute. I suggest you use the following:
number: unsigned char (a char is just a byte of data and football numbers go from 1-99)
name: string (AKA char*)
pos: string
ht: string
wt: integer (some players weight more than 256)
age: unsigned char
exp: string
college: string
Make a struct using the above attributes.
Now you should allocate an array that can hold all this data for all the players. How will you do
that?
Then read in the players data, and store them in the array you just created.
Part 3: Query the Data
For this part, prompt the user for a player number, the after the number is entered ,search your
player array for that number, then print out all the associated player data based on that query. If
the there is no player associated with that return an error message. Your program should continue
letting the user query the data until the user types -1.
I did this one for my self. I did part one.
But I have no idea how to handle part 2 and 3
Here is my code.
Code:#include <stdio.h> #include <stdlib.h> int main() { FILE *fp; int count = 0; char c; fp = fopen("cheifs2015.csv","r"); for (c = getc(fp); c != EOF; c = getc(fp)) { if ( c == '\n') count = count + 1; } fclose(fp); printf("%d players\n", count); struct players { unsigned char number; char *name; char *pos; char *ht; int wt; unsigned char age; char *exp; char *college; }; struct players *x = malloc(sizeof(*x)); // allocated array return 0; }
I can't attach files so here is file information.
#,NAME,POS.,HT.,WT.,AGE,EXP.,COLLEGE
39,"Abdullah, Husain",DB,6-0,204,30,7,Washington State
57,"Alexander, D.J.",LB,6-2,233,23,R,Oregon State
71,"Allen, Jeff",OL,6-4,306,25,4,Illinois
81,"Avant, Jason",WR,6-0,210,32,10,Michigan
97,"Bailey, Allen",DL,6-3,288,26,5,Miami (Fla.)
29,"Berry, Eric",DB,6-0,211,26,6,Tennessee
27,"Branch, Tyvon",DB,6-0,210,28,8,Connecticut
9,"Bray, Tyler",QB,6-6,215,23,3,Tennessee
4,"Brown, Da'Ron",WR,6-0,199,23,R,Northern Illinois
77,"Catapano, Mike",DL,6-4,270,25,3,Princeton
25,"Charles, Jamaal",RB,5-11,199,28,7,Texas
2,"Colquitt, Dustin",SP,6-3,210,33,11,Tennessee
26,"Commings, Sanders",DB,6-0,223,25,3,Georgia
17,"Conley, Chris",WR,6-3,205,22,R,Georgia
6,"Cook, Kenny",WR,6-4,218,23,R,Gardner-Webb
31,"Cooper, Marcus",DB,6-2,192,25,3,Rutgers
10,"Daniel, Chase",QB,6-0,225,28,7,Missouri
59,"Davis, Ja'Gared",LB,6-0,238,24,1,Southern Methodist
34,"Davis, Knile",RB,5-10,227,23,3,Arkansas
70,"DeVito, Mike",DL,6-3,305,31,9,Maine
75,"Dima, Anthony",OL,6-6,295,24,1,Massachusetts
76,"Duvernay-Tardif, Laurent",OL,6-5,315,24,2,McGill (Canada)
48,"East, Andrew",SP,6-2,220,23,R,Vanderbilt
74,"Fanaika, Paul",OL,6-5,327,29,5,Arizona State
93,"Fangupo, Hebron",DL,6-0,324,30,2,Brigham Young
72,"Fisher, Eric",OL,6-7,315,24,3,Central Michigan
30,"Fleming, Jamell",DB,5-11,206,26,4,Oklahoma
55,"Ford, Dee",LB,6-2,243,24,2,Auburn
69,"Frye, Garrett",OL,6-5,290,22,R,Georgia Southern
73,"Fulton, Zach",OL,6-5,316,23,2,Tennessee
23,"Gaines, Phillip",DB,6-0,193,24,2,Rice
89,"Gordon, Richard",TE,6-4,268,28,5,Miami (Fla.)
66,"Grubbs, Ben",OL,6-3,310,31,9,Auburn
91,"Hali, Tamba",LB,6-3,275,31,10,Penn State
85,"Hammond, Frankie",WR,6-1,185,25,2,Florida
84,"Harris, Demetrius",TE,6-7,230,24,2,Wis.-Milwaukee
88,"Hemingway, Junior",WR,6-1,225,26,3,Michigan
44,"Hester, Aaron",DB,6-1,207,25,1,UCLA
50,"Houston, Justin",LB,6-3,258,26,5,Georgia
96,"Howard, Jaye",DL,6-3,301,26,4,Florida
74,"Irving, David",DL,6-7,273,22,R,Iowa State
56,"Johnson, Derrick",LB,6-3,242,32,11,Texas
52,"Johnson, James-Michael",LB,6-1,240,26,4,Nevada
87,"Kelce, Travis",TE,6-5,260,25,3,Cincinnati
64,"Kush, Eric",OL,6-4,313,25,3,California (Pa.)
15,"Luckett, Donatella",WR,6-0,211,24,R,Harding
19,"Maclin, Jeremy",WR,6-0,198,27,7,Missouri
59,"March, Justin",LB,6-0,230,22,R,Akron
95,"Martin, Josh",LB,6-3,245,23,3,Columbia (N.Y.)
94,"Martin, Vaughn",DL,6-4,300,29,6,Western Ontario (Canada)
90,"Mauga, Josh",LB,6-1,245,28,6,Nevada
24,"McCray, Kelcie",DB,6-1,205,26,4,Arkansas State
61,"Morse, Mitch",OL,6-6,305,23,R,Missouri
54,"Moses, Dezman",LB,6-2,249,26,3,Tulane
77,"Munyer, Daniel",OL,6-2,295,23,R,Colorado
7,"Murray, Aaron",QB,6-1,210,24,2,Georgia
20,"Nelson, Steven",DB,5-11,194,22,R,Oregon State
99,"Nunez-Roches, Rakeem",DL,6-2,307,22,R,Southern Mississippi
80,"O'Shaughnessy, James",TE,6-4,245,23,R,Illinois State
40,"Olatoye, Deji",DB,6-1,194,24,R,North Carolina A&T
38,"Parker, Ron",DB,6-0,206,28,5,Newberry
45,"Penny, Kenneth",DB,5-11,173,24,R,UNLV
22,"Peters, Marcus",DB,6-0,197,22,R,Washington
92,"Poe, Dontari",DL,6-3,346,25,4,Memphis
60,"Pughsley, Jarrod",OL,6-4,310,24,1,Akron
32,"Reaves, Darrin",RB,5-10,220,22,R,Alabama-Birmingham
62,"Reed, Marcus",OL,6-3,345,23,R,Fayetteville State
65,"Rooks, Tavon",OL,6-5,300,25,1,Kansas State
5,"Santos, Cairo",SP,5-8,160,23,2,Tulane
47,"Schiltz, Adam",TE,6-4,256,25,1,Emporia State
42,"Sherman, Anthony",RB,5-10,242,26,5,Connecticut
67,"Sherrod, Derek",OL,6-6,321,26,5,Mississippi State
46,"Short, Kevin",DB,6-2,190,23,R,Fort Scott CC
11,"Smith, Alex",QB,6-4,217,31,11,Utah
8,"Smith, Jeret",WR,6-0,215,22,R,McMurry
21,"Smith, Sean",DB,6-3,218,28,7,Utah
49,"Sorensen, Daniel",DB,6-2,208,25,2,Brigham Young
79,"Stephenson, Donald",OL,6-6,312,26,4,Oklahoma
82,"Taylor, Ryan",TE,6-3,254,27,5,North Carolina
13,"Thomas, De'Anthony",RB/WR,5-8,176,22,2,Oregon
75,"Tuaau, Charles",DL,6-5,310,23,R,Texas A&M Comm.
30,"Ware, Spencer",RB,5-10,229,23,2,LSU
1,"Washington, L’Damian",WR,6-4,204,24,1,Missouri
35,"West, Charcandrick",RB,5-10,205,24,2,Abilene Christian
83,"Williams, Fred",WR,6-0,190,,,St. Cloud State University
98,"Williams, Nick",DL,6-4,309,25,2,Samford
12,"Wilson, Albert",WR,5-9,200,23,2,Georgia State
53,"Wilson, Ramik",LB,6-2,237,23,R,Georgia
41,"Winchester, James",SP,6-3,240,26,1,Oklahoma
51,"Zombo, Frank",LB,6-3,254,28,6,Central Michigan