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*/
2 comment threads