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

37%
+1 −3
Q&A How can I delete a book from the collection by a particular title from my library file?

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<...

0 answers  ·  posted 3y ago by hamburgersarecool‭  ·  edited 3y ago by hamburgersarecool‭

#3: Post edited by user avatar hamburgersarecool‭ · 2021-12-09T14:08:37Z (about 3 years ago)
  • 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<stdio.h>
  • #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;
  • /*
  • ```
  • 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<stdio.h>
  • #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: Post edited by user avatar hamburgersarecool‭ · 2021-12-09T14:07:15Z (about 3 years ago)
  • I would like to delete a book from the collection by a particular title
  • from my library, as Case 2 of my switch statement. How can I do that with my current code?
  • ```#include<stdio.h>
  • #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;
  • /*
  • ```
  • 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<stdio.h>
  • #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;
  • /*
  • ```
#1: Initial revision by user avatar hamburgersarecool‭ · 2021-12-09T14:06:39Z (about 3 years ago)
How can I delete a book from the collection by a particular title from my library file?
I would like to delete a book from the collection by a particular title
from my library, as Case 2 of my switch statement. How can I do that with my current code?

```#include<stdio.h>
#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;
/*
```