\n

Reply

Join Date: Oct 2009
Posts: 2
Reputation: luoyangke is an unknown quantity at this point 
Solved Threads: 0
luoyangke luoyangke is offline Offline
Newbie Poster

\n

 
0
  #1
Oct 25th, 2009
who can tell me what the use of "\n" is? and what the difference between
  1. scanf("%d",&j);
and
  1. scanf("%d\n",&j)
;?
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 379
Reputation: tomtetlaw is an unknown quantity at this point 
Solved Threads: 4
tomtetlaw's Avatar
tomtetlaw tomtetlaw is offline Offline
Posting Whiz
 
-1
  #2
Oct 25th, 2009
In C, the '\n' character is a special type of character called a control character, these are characters that do something other then just display themselves, here is all the ones that I know:

\n = newline
\t = tab
\a = This one rocks, it makes the computer make a beeping sound

The difference between those follows:

Say you called the first one, then the user entered 'hello', j would now be 'hello', if you called the second one, j would be 'hello\n' and whenever you printed out j after the second one, it would print out hello followed by a newline
Last edited by tomtetlaw; Oct 25th, 2009 at 6:54 am.
...
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,401
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1467
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning
 
-7
  #3
Oct 25th, 2009
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 47
Reputation: Iam3R is an unknown quantity at this point 
Solved Threads: 2
Iam3R Iam3R is offline Offline
Light Poster
 
-1
  #4
Oct 25th, 2009
if i use this in a program its keep on taking the return key
the program not getting terminated, whats the problem?
  1. scanf("%d\n",&j)
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,612
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 468
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven
 
0
  #5
Oct 25th, 2009
It discards unwanted white space.
A white-space character in the control string causes scanf() to skip over one or more leading white-space characters in the input stream.

  1. int main()
  2. {
  3. char ch,ch1;
  4.  
  5. printf("Enter two chars : ");
  6. scanf("%c\n%c",&ch,&ch1);
  7. printf("\n%c\n%c",ch,ch1);
  8. return 0;
  9. }
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 2
Reputation: luoyangke is an unknown quantity at this point 
Solved Threads: 0
luoyangke luoyangke is offline Offline
Newbie Poster

thank you

 
0
  #6
Oct 25th, 2009
thank you for the anwser
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,359
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 239
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c
 
1
  #7
Oct 25th, 2009
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC