The code attached with this post is part of a bigger program but I am experiencing problems while taking in input for my structured variable 'title' and 'author'. The program seems to loop over it and move on to the next line. Also, while using [^\n] before 's' in the string specifier, it does the same however I read it is used to take a string as input using scanf. Read a few posts but can't figure out the issue. Just starting with C, any help would be appreciated!
struct books{
char title[30];
char author[30];
char subject[20];
int quantity;
int book_id;
char *category;
int count;
float price;
};
struct books book;
book.book_id=id;
printf("\n\n\t\tBook Name:\n\t\t");
scanf(" %s",book.title);
printf("\n\n\t\tAuthor:\n\t\t");
scanf(" %[^\n]s",book.author);
printf("\n\n\t\tQuantity:\n\t\t");
scanf("%d",&book.quantity);
printf("\n\n\t\tPrice:\n\t\t");
scanf("%f",&book.price);