Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Overview: In this assignment, you will create a collection of books using a Book struct: typedef struct { char * title; char * author; int
Overview:
In this assignment, you will create a collection of books using a Book struct:
typedef struct
char title; char author;
int year;
Book;
Book createlibrary char ;
This function reads in booklist. txt provided and creates an array of Book structs. It returns a pointer to this array.
void display books Book ;
This function takes the pointer to the array of books, and prints them to the screen.
void reversebooks Book ;
This function creates a reversed book list and returns a pointer to the reversed array.
savetofileFILE Book ;
This function saves the reversed list to a file.
You will need to pass the name of the file on the command line and pass it as an argument to createlibrary You are free to implement helper functions if you wish.
Compile your program using: gcc Wall pedantic library. c stdc Library
To run the program: library booklist.txt reversed list.txt
Example Run:
Original Library
Title: To Kill a Mockingbird, Author: Harper Lee, Year:
Title: Author: George Orwell, Year:
Reversed Library
Title: Beloved, Athor Tani Morason, var Now that you have your program displaying the output to the screen, add the savetofile functionality to have your program save the reversed list to a file called reversedlist. txt The filename should be passed in on the command line when you run the program:
library booklist.txt reversed list.txt
Note: the program should also run without the second filename provided, in which case it just wouldn't producethatfile library.c file: typedef struct
char title;
char author;
int year;
Book;
Book createlibrarychar filename;
void displaybooksBook library;
Book reversebooksBook library;
void savetofilechar filename Book library;
int main
create the library
Book library createlibrary;
printf Original Library
;
display the library onto the screen
displaybookslibrary;
Create a reversed library
Book reversedlibrary;
printf
Reversed Library
;
displaybooksreversedlibrary;
Save the reversed library to a file
savetofile;
Book createlibrarychar filename
void displaybooksBook library
Book reversebooksBook library
Book reversedlibrary malloc sizeofBook;
void savetofilechar filename Book library
book.txt file:To Kill a Mockingbird, Harper Lee,
George Orwell,
Pride and Prejudice, Jane Austen,
The Great Gatsby, F Scott Fitzgerald,
Moby Dick, Herman Melville,
War and Peace, Leo Tolstoy,
The Catcher in the Rye, JD Salinger,
The Lord of the Rings, JRR Tolkien,
Jane Eyre, Charlotte Bront
The Hobbit, JRR Tolkien,
Animal Farm, George Orwell,
Crime and Punishment, Fyodor Dostoevsky,
The Brothers Karamazov, Fyodor Dostoevsky,
Brave New World, Aldous Huxley,
Wuthering Heights, Emily Bront
Great Expectations, Charles Dickens,
The Odyssey, Homer,
The Iliad, Homer,
Ulysses, James Joyce,
Madame Bovary, Gustave Flaubert,
The Divine Comedy, Dante Alighieri,
The Count of Monte Cristo, Alexandre Dumas,
Les Misrables Victor Hugo,
Anna Karenina, Leo Tolstoy,
The Grapes of Wrath, John Steinbeck,
One Hundred Years of Solitude, Gabriel Garcia Marquez,
The Picture of Dorian Gray, Oscar Wilde,
Fahrenheit Ray Bradbury,
SlaughterhouseFive, Kurt Vonnegut,
The Scarlet Letter, Nathaniel Hawthorne,
Dracula, Bram Stoker,
Frankenstein, Mary Shelley,
Catch Joseph Heller,
The Sun Also Rises, Ernest Hemingway,
East of Eden, John Steinbeck,
The Old Man and the Sea, Ernest Hemingway,
A Tale of Two Cities, Charles Dickens,
The Adventures of Huckleberry Finn, Mark Twain,
The Adventures of Tom Sawyer, Mark Twain,
Mansfield Park, Jane Austen,
Sense and Sensibility, Jane Austen,
Emma, Jane Austen,
Northanger Abbey, Jane Austen,
Persuasion, Jane Austen,
Heart of Darkness, Joseph Conrad,
The Metamorphosis, Franz Kafka,
The Trial, Franz Kafka,
Invisible Man, Ralph Ellison,
Beloved, Toni Morrison,
Lolita, Vladimir Nabokov,
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