I learnt (self-learning) the basics of structure in C today and wrote this simple code. it is compiling without any error. I know that successful compilation is no guarantee for a bug-free software. While execution, it scans the inputs for two structure variables only and gives erroneous display. for the sake of simplicity I chose a char to store the book name. I am not able to figure out the bug here. could you find one?

Just because you get no errors when compiling, that doesn't mean your program will actually do what you want. This is normally called a bug.
–
Greg HewgillMay 1 '12 at 3:42

@GregHewgill I am aware of the fact that compilation is no guarantee for bug-free software. I was interested in knowing the bug in the above mentioned code, which is not so apparent. if you could see a bug, kindly mention it..
–
SaurabhMay 1 '12 at 10:28

awesome.. it worked!!! thanks a lot.. could you discuss a bit more, what exactly was going wrong. ( for extending my learning from this problem)
–
SaurabhMay 1 '12 at 4:06

1

@Saurabh - Glad you got it working. The solution is "Flushing" the input stream/buffer.
–
AVDMay 1 '12 at 4:10

1

@Saurabh - the scanf() only reads from stdin (the keyboard) until it has matched everything in the format string (a character, a space, a floating point number, a space, then an integer in your case). That leaves the carriage return / line-feed floating in the input buffer, and AVD's while() loop eats data until that has also been received: then you're ready for the next entry.
–
AATMay 1 '12 at 10:38