March 23rd, 2013, 10:44 AM
Strange result with scanf() function.why?
i am able to provide input values only for 3 times but in for loop i have written code to enter input for five times.
printf("\n%c %d %d",name[i],price[i],pages[i]);
a 1 1
b 2 2
c 3 3 //till here it is taking input(first for loop)
a 1 1 //from here it is printing(second for loop)
b 2 2
c 3 3
when trying to give the input values fourth time, it is directly printing my given values that in strange order.why?
March 23rd, 2013, 11:06 AM
When you push the enter button in the terminal and therefore inserting a new line character. The next call to scanf continue to read what is in the buffer (that is, the new line from the previous entry in the terminal), you can skip that from your result by putting a space character before %c in your scanf call.
So instead of
March 23rd, 2013, 11:28 AM
yaaa....its working.thankyou verymuch. :)