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

Dashboard
Notifications
Mark all as read
Q&A

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

+1
−2

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*/
Why does this post require moderator attention?
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)

0 answers

Sign up to answer this question »