Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

62%
+3 −1
Q&A Problems with data structures and filestreams.

My advice to you is to break this down into smaller problems and try to solve them one at a time, making sure you have a program that can compile and run at each step. First: figure out how to suc...

posted 2y ago by r~~‭

Answer
#1: Initial revision by user avatar r~~‭ · 2021-12-13T18:48:36Z (over 2 years ago)
My advice to you is to break this down into smaller problems and try to solve them one at a time, making sure you have a program that can compile and run at each step.

First: figure out how to successfully read and write a single book. Write a function that reads book information from stdin and returns a `struct book`. Write another function that accepts a `struct book` as an argument and writes all that information to a file somehow. Write a third function that reads from that file and returns a `struct book`. Write a fourth function that accepts a `struct book` and prints its information to stdout. You should be able to write a program that uses these four functions and prints the same information, in the same order, that you give it. (Based on the state of your code and the questions you've asked so far, I suspect this is the hard part for you—it has nothing to do with the deleting operation.)

Second: now figure out how to successfully read and write an entire library. Adapt the above functions to handle `struct library *` pointers instead of `struct book` values, and test your program again to make sure that it prints what you give it.

Third: figure out how to write a function that edits a `struct library *` in the way that you want. You can do this either by accepting and returning `struct library *` pointers, or just by accepting a `struct library **` double pointer. This function should do *nothing* with files or with `scanf` (you can use `printf` if it helps you understand what's going on). Test this function by incorporating it into the program you wrote in the second part. If it doesn't work the way you expect, revisit the function.