Click here to Skip to main content
15,881,380 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am new here and a beginner programmer and i have some problem with the piece of code where i have used %c in scanf to get the char .Someone on the internet was talking about the whitespaces which i am not completely understanding

this is my code http://i.imgur.com/oQTjpDc.png[^]

and is result http://i.imgur.com/qwsp5i2.png[^]

the someone said %c is reading the \n function as a whitespace but in another simple program it is not http://i.imgur.com/DnVQXBN.png[^]

and in the program of the operator above a blank space before %c in the second scanf seems to be working but isn't a blank space also white space so it has to take in the blank space as char and sign (is what i am thinking) but the program seems to be perfectly working

what is that i am missing ?

can anyone explain the whitespace concept clearly ?

thank for anyone who replies.
Posted
Comments
PIEBALDconsult 17-Sep-15 23:16pm    
Not going to click those.

 
Share this answer
 
"White space" is simply another way to say "Space". It is the space that you type between words. "White space" simply refer to the fact that on a book, letters are printed in Black and a space print nothing and thus stay White.

There is no other concept than that.

If you have a problem with a program, include it in the question, no link, copy the source code directly. And explain the problem.
 
Share this answer
 
Comments
Member 11991760 17-Sep-15 23:10pm    
ohh thanks i did not know that rule of posting directly i saw the link thing and i posted sorry i am new here, maybe thats why people of stack overflow were hating me sorry ill ask again this time perfectly
Patrice T 17-Sep-15 23:22pm    
Not exactly a rule, more of a safety measure.
Some people abuse links and make links that lead to malware, so people here try to avoid links.
Secondary effect, when the link is a picture, helper have to retype the source code in order to help. Rather than simply do a Copy/Paste.
Member 11991760 17-Sep-15 23:34pm    
Thanks i did not know that i will be more careful from next
white spaces in scanf:
It is just a problem with scanf function which makes the function to end with an first input on the first white space(white spaces include blank, tabs, carriage return, spaces, form feeds, new line character etc., etc.,)

when you type the following line as input :
"can someone explain the concept of white spaces"
the only string can will be taken as input because the space ends the string.
This problem can be solved using getchar function.Please mind of using loop while using getchar since reads/stores only a single character at a time.

I can't figure out your question completely because you have not provided the code in your question.I believe this may help you.Kindly excuse me for not clicking those links provided by you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900