I'm not surprised it gives a segmentation fault. In
main
you have;
struct book *x;
printf("name : ");
gets(x->name);
...
So you have created the pointer
x
but it does not point to anything, hence the seg fault. You need to initialise it so that it points to an actual memory structure. This is done by a call to
malloc
thus:
struct book *x;
x = (struct book *)malloc(sizeof(struct book));
printf("name : ");
gets(x->name);