Question
Baseball has been called Americas pastime and each year millions of fans collect trading cards of their favorite team and/or player and often store them
Baseball has been called Americas pastime and each year millions of fans collect trading cards of their favorite team and/or player and often store them in shoe-boxes. For this project, you will create a program that uses a data structure and a random-access file to store and retrieve data about the five baseball cards sitting in your shoe-box.
Create a structure called Card that contains the following members:
- recordNum (year-card#)
- cardNumber
- cardYear
- playerName
- position
Using the above structure, modify the following C program that is shown at the botttom and program it to enter and display the following:
Card List | ||||
Year | Card | Card# | Player | Position |
1958 | Topps | 88 | Duke Snider | Outfield |
1958 | Topps | 25 | Don Drysdale | Pitcher |
1988 | Fleer | 523 | Steve Sax | Second Base |
1988 | Donruss | 229 | Mike Marshall | Outfield |
1988 | Topps | 605 | Kirk Gibson | Outfield |
#include
struct clientData { unsigned int acctNum; char lastName[15]; char firstName[10]; double balance; };
int main(void) { FILE *cfPtr;
if ((cfPtr = fopen(\"accounts.dat\", \"wb\")) == NULL) { puts(\"File could not be opened.\"); } else { struct clientData blankClient = {0, \"\", \"\", 0.0};
for (unsigned int i = 1; i => fwrite(&blankClient, sizeof(struct clientData), 1, cfPtr); } fclose (cfPtr); } if ((cfPtr = fopen(\"accounts.dat\", \"rb+\")) == NULL) { puts(\"File could not be opened.\"); } else { struct clientData client = {0, \"\", \"\", 0.0};
printf(\"%s\", \"Enter account number\" \" (1 to 100, 0 to end input): \"); scanf(\"%d\", &client.acctNum);
while (client.acctNum != 0) { printf(\"%s\", \"Enter lastname, firstname, balance: \"); fscanf(stdin, \"%14s%9s%lf\", client.lastName,
client.firstName, &client.balance); fseek(cfPtr, (client.acctNum - 1) * sizeof(struct clientData), SEEK_SET); fwrite(&client, sizeof(struct clientData), 1, cfPtr);
printf(\"%s\", \"Enter account number: \"); scanf(\"%d\", &client.acctNum); } fclose(cfPtr); } if ((cfPtr = fopen(\"accounts.dat\", \"rb\")) == NULL) { puts(\"File could not be opened.\"); } else { printf(\"%-6s%-16s%-11s%10s \", \"Acct\", \"Last Name\", \"First Name\", \"Balance\"); while (!feof(cfPtr)) { struct clientData client = {0, \"\", \"\", 0.0}; int result = fread(&client, sizeof(struct clientData), 1, cfPtr); if (result != 0 && client.acctNum != 0) { printf(\"%-6d%-16s%-11s%10.2f \", client.acctNum, client.lastName, client.firstName, client.balance); } } fclose(cfPtr); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started