This is simple code, when we create a pointer book1 from structure book and then we allocate it memory but when this pointer book1 is passed to the function get_info and when fgets should get value from the user, it simply skips it without taking value using fgets but working perfect with %s.
#include <stdio.h>
#include <stdlib.h>
struct book{
char title[100];
char author[100];
};
void get_info (struct book *b1){
printf("Enter the author: ");
fgets(b1->author, sizeof(b1->author) , stdin);
printf("Enter the title: ");
scanf("%s",b1->title);
}
void display_book (struct book *b1){
printf("Title: %s\n", b1->title);
printf("Author: %s\n",b1->author);
}
int main(){
struct book *book1;
int n;
printf("Enter number of book to enter: ");
scanf("%d",&n);
book1=(struct book*)malloc(n*sizeof(struct book));
for (int i=0; i<n; i++){
get_info(book1+i);
display_book(book1+i);
}
return 0;
}