943,815 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 24634
  • C RSS
Sep 30th, 2007
0

newline character

Expand Post »
what is a newline character and what does it do?
for example, what does " variable != '\n' " mean?

And is there any other way to write" if (variable != '0' && variable != '1' && variabel != '\n') "?
I've tried " if (variable < '0' && variable > '1' && variabel != '\n') " , but it wouldn't work.
thanks
Last edited by megan-smith; Sep 30th, 2007 at 7:06 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
megan-smith is offline Offline
13 posts
since Sep 2007
Sep 30th, 2007
0

Re: newline character

In a word processor when you hit the <Enter> key the cursor will move one line down and all the way to the left margin. That is what the '\n' character simulates in text files. When you load a text file that contains newlines in Notepad or some other word processor you will see that behavior. Remove the newlines and everything will appear on the same line.

Exactly what is put in text files depends on the operating system -- MS-Windows adds two characters to the text file while both *nix and MAC add only one character.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is online now Online
21,950 posts
since Aug 2005
Sep 30th, 2007
0

Re: newline character

thanks for the explanation.
now i understand what it means.
but what about " variable != '\n' " in an if command?
what does it mean " if variable is not '/n'?
and is there any other way of writing " if (variable != '0' && variable != '1' && variabel != '\n') "?
i told ya what i tried but it did not work!

thanks again.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
megan-smith is offline Offline
13 posts
since Sep 2007
Sep 30th, 2007
0

Re: newline character

>>what does it mean " if variable is not '/n'?
If the '\n' character has not been encountered -- normally signifies the end of a string in text files. '\0' indicates the end of the string in memory, assuming it is a normal c-style character array.

>>and is there any other way of writing
Could be done like this:
  1. char str[] = "01\n";
  2. if( strchr(str,variable) != 0)
  3. {
  4. // found it
  5. }
Last edited by Ancient Dragon; Sep 30th, 2007 at 9:17 pm.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is online now Online
21,950 posts
since Aug 2005
Oct 1st, 2007
0

Re: newline character

Thanks!
I appreciate it.
Last edited by megan-smith; Oct 1st, 2007 at 1:29 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
megan-smith is offline Offline
13 posts
since Sep 2007

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: changing values of a struct
Next Thread in C Forum Timeline: Help!!!!!!!!!!!!!





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


Follow us on Twitter


© 2011 DaniWeb® LLC