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.

Comments on How can I delete a book from the collection by a particular title from my library file?

Post

How can I delete a book from the collection by a particular title from my library file?

+1
−3

I would like to delete a book from the collection by a particular title from my library if the user enters 2 as input for my switch statement. How can I do that with my current code?

#include<stdlib.h>
#define MAX 49
//void addBook(struct library* thislib){
//}
struct book{
     char *title;
     char *author;
     char *subject; //subject[]
};

struct library {
    struct book collection;
    int num_books;
    struct library *next; //store address of next node
};

struct book collection; //supposed to be aBook
struct book *aPtr;
struct library aCollection;
struct library *aaPtr;

int main (void){
    
   FILE *cfPtr; //pointer points to the newly created file

   char strtitle[MAX]; 
   char strauthor[MAX];
   char strsubject[MAX];
   int operation;

   
    if ((cfPtr = fopen("library.dat","w")) == NULL){
        printf("File could not be opened...\n");
    }
   else {

       while (!feof()){
        operate();
        printf("Enter an operation: ");
        scanf("%d", &operation);

          /*case 1: coding of the switch statement*/

            case 2: //here
            if(!isEmpty(aPtr)){ //if list is not empty
                aaPtr = NULL;
                print("%s", "Enter title of the book to delete:\n");
                scanf("%s", &strtitle);

                aCollection.collection = strtitle;
                delete(strtitle);
                printf("The book %s has been removed from the library.", aBook.title);
                fprintf(cfPtr, "The book %s has been removed from the library.", aBook.title);
                }
                else{
                    printf("Item not found!");
                }
                else{
                    puts("List is empty.\n");
                }
            }
            break;

/*unfinished coding, I'm still working on this code*/
History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

2 comment threads

What Canina said, but just a few more additional tips... (2 comments)
Post Feedback (1 comment)
Post Feedback
Canina‭ wrote almost 3 years ago

As it stands, this question is rather broad. We're not here to write your code (do your homework) for you. However, if you can name one SPECIFIC issue that you are having difficulties with, that's a different matter. Can you edit your question to narrow it down to something specific, rather than a broad "please write my code for me" type of question?