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 do I display the book (its title, author & subject) from my libraryy.txt document by entering the title of that book on the screen? [closed]

+0
−2

Closed as unclear by Alexei‭ on Dec 12, 2021 at 16:42

This question cannot be answered in its current form, because critical information is missing.

This question was closed; new answers can no longer be added. Users with the reopen privilege may vote to reopen this question if it has been improved or closed incorrectly.

I want my compiler to display an output of the book contents (its title, author & subject) when I enter the title of that particular block in the compiler's output screen. However there seems to be in error & I'm stuck. Can someone help me out? Thanks, would really appreciate any help :")

#include<stdlib.h>
#include<conio.h>
#define MAX 49 //title, author & subject cannot exceed 49 char

struct book{
     char *title;
     char *author;
     char *subject;
};

    struct library {
    struct book collection;
    int num_books;
    struct library *next;
};


struct book collection;
struct book *aPtr;
struct library aCollection;
struct library *aaPtr;

//function to display
void displaysub(){
    char *keyword=NULL;
    library* current=head;  //error on this line...
    printf("Enter a title name of the book to search: ");
    fflush(stdin);
    keyword=(char*) malloc(MAX*sizeof(char));
    gets(keyword);
    for (current=head;current!=NULL;current=current->next)
    {
        if ((strcmp(current->title,keyword)==0)) {
           puts(current->operation);
           puts(current->title);
           puts(current->author);
           puts(current->subject);
        }
    }

}

int main (void){

   FILE *cfPtr;

    if ((cfPtr = fopen("libraryy.txt","a")) == NULL){
        printf("File could not be opened...\n");
    }

   else {
/*my coding which I didn't include here to avoid lengthy posts*/
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

library* current=head; //error on this line... (2 comments)
I did, but I don't understand it. If I did, I wouldn't need to ask it here. That's why I'm asking for... (2 comments)

0 answers