A whitespace character (including \n) in the format string will cause scanf to discard any whitespace in the input stream upto the next token. If a whitespace character is the last character in the format string that means that the user must already enter the next token, so that scanf knows upto where it needs to discard whitespace.
Genereally you simply don't want to have whitespace characters at the end of your format string.
does this mean that the user needs to enter another input (may be a string or an integer or so) so that the scanf returns?
It means there needs to be at least one non-whitespace character after all of the whitespace characters. When you put whitespace in the format string, you can think of it as a specifier saying "read and discard all contiguous whitespace". If a newline is the last character then scanf() doesn't have any way of knowing it's the last and will wait for you to give it more.
@jame sir, but why is it so ? i mean why scanf is waiting for input ? why is it expecting a character ?
and secondly , new line is a white space or non-white space character ? i am confused!
i mean why scanf is waiting for input ? why is it expecting a character ?
Because, as has been explained repeatedly now, a white space in scanf's format string means "consume any whitespace characters until you find the next non-whitespace character". Why does it mean that? Because the C standard says that that's what it means.
new line is a white space or non-white space character ?
The newline character is a whitespace character. For more information on what is and isn't a whitespace character see the documentation of the isspace function.
Hey, so I wanna ask how I need to create a method who will remove word if in that word is 2 same chars. Example: "Potato" in this word there is a 2 "o" chars so this word will need to be removed. "Forum" in this word there is no ...
Hi I'm having a problem implementing a mini shopping cart drop down in the header to show the user all the products they have in their shopping cart. It seems the only solution for this is Ajax, and I've looked all over and can't find anything that I could possibly ...