I am new to programming in C, so I decided to make a book library for practice. Working on a function to add a new book i need to get the book name, the authot name and the book quantity. But the program prints asking for all of them and i want to ask for another after the input is given, on the screen it should look like this:
Author: input author name
Title: input book title
Quantity: input book quantity
To get the author and book names I am using fgets, because both of them are strings, but for some reason it keeps printing and the result I am getting is:
Author:
Title:
input line for author name
input line for book title
Quantity: input book quantity
Is there a problem with my code? Or a way to make it the way I want?
book generate_book(book entry, library lib) {
printf("You must tell me the info about the book\n");
printf("Author: ");
fgets(entry.author, 50, stdin);
fflush(stdin);
printf("Title: ");
fgets(entry.title, 50, stdin);
fflush(stdin);
printf("Quantity: ");
scanf("%d", &entry.quantity);
fflush(stdin);
entry.id = lib.used_space + 1;
entry.issued = 0;
return entry;
}
This function is called after a choice made in a menu using switch case with integer variables