Please Write in C language 1.) Open a file in read binary mode 2.) Read the data
ID: 3793235 • Letter: P
Question
Please Write in C language
1.) Open a file in read binary mode
2.) Read the data from that file into a structure
3.) Print out the given structure
Structure I am using for this program:
typedef struct Player{
char Player_Name[50];
int Homeruns;
int triples;
int doubles;
}player;
function to use in the program: player* read_binary_file(char* input_file);
//RETURNS A player pointer
//PARAMATER à input_file (from command line)
//FLOW OF FUNCTION:
Error check parameter to ensure input file is not null
Open give file in read binary mode
Ensure file pointer is not null
Allocate memory for a single structure pointer
Utilize fread() function to read data from open file pointer
Pass back populated structure pointer to main
int main(int argc, char* argv[])
FLOW OF MAIN:
Error check parameters
Call read_binary_file function
Use printf() to print out the structure that was passed back
Example Output
[ajwvz9@tc-login Lab_3]$ compile prelab3.c
[ajwvz9@tc-login Lab_3]$ ./a.out
Incorrect Input
Correct input:
./a.out <binaryinputfile>
[ajwvz9@tc-login Lab_3]$ ./a.out binary.bin
Player Name = Jeremy Warden
Homeruns = 70
Triples = 80
Doubles = 120
[ajwvz9@tc-login Lab_3]$
Explanation / Answer
output is:
Player Name Jeremy Warden
Homeruns 70
Triples 80
Doubles 120
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.