0

hi there am wondering about the space between the " and the %


scanf(" %c",&choice);

what's the different if i leave no space?

3
Contributors
6
Replies
8
Views
6 Years
Discussion Span
Last Post by Narue
0

Try it and see. Include leading whitespace in your input string.

p.s. Come up with better thread titles. I very nearly reported this thread as a duplicate, and I'll refuse to help for future questions titled "need help with Dev C++".

0

There are some special characters like '\' which we use for '\n' etc. If we leave a space then the compiler will not recognize it as a special command and just treats it as a character in a string.

Edited by Arbus: n/a

0

There are some special characters like '\' which we use for '\n' etc. If we leave a space then the compiler will not recognize it as a special command and just treats it as a character in a string.

Um, no.

0

just treats it as a character in a string.

Yes, I have made a mistake there. The compiler doesn't treat it as a character.

0

The compiler doesn't treat it as a character.

Closer. A whitespace character in the scanf format string is treated as "any kind and amount of whitespace". scanf format specifiers trim leading whitespace, with the exception of %c, %[, and %n, so " %c" is a way of adding that functionality to a specifier that doesn't normally include it.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.