943,998 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 376
  • C RSS
Oct 25th, 2009
0

\n

Expand Post »
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)
;?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
luoyangke is offline Offline
2 posts
since Oct 2009
Oct 25th, 2009
-1
Re: \n
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.
Reputation Points: 9
Solved Threads: 5
Posting Pro
tomtetlaw is offline Offline
591 posts
since Sep 2008
Oct 25th, 2009
-7
Re: \n
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,953 posts
since Aug 2005
Oct 25th, 2009
-1
Re: \n
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)
Reputation Points: 34
Solved Threads: 4
Junior Poster
Iam3R is offline Offline
110 posts
since Oct 2009
Oct 25th, 2009
0
Re: \n
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. }
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Oct 25th, 2009
0

thank you

thank you for the anwser
Reputation Points: 10
Solved Threads: 0
Newbie Poster
luoyangke is offline Offline
2 posts
since Oct 2009
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Reading few string from a .txt file
Next Thread in C Forum Timeline: difficulty in understanding functions in c language





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC