RSS Forums RSS

newline character

Please support our C advertiser: Programming Forums
Reply
Posts: 13
Reputation: megan-smith is an unknown quantity at this point 
Solved Threads: 0
megan-smith megan-smith is offline Offline
Newbie Poster

newline character

  #1  
Sep 30th, 2007
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 6:06 pm.
AddThis Social Bookmark Button
Reply With Quote  
Posts: 13,885
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: 1231
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Most Valuable Poster

Re: newline character

  #2  
Sep 30th, 2007
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.
Reply With Quote  
Posts: 13
Reputation: megan-smith is an unknown quantity at this point 
Solved Threads: 0
megan-smith megan-smith is offline Offline
Newbie Poster

Re: newline character

  #3  
Sep 30th, 2007
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.
Reply With Quote  
Posts: 13,885
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: 1231
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Most Valuable Poster

Re: newline character

  #4  
Sep 30th, 2007
>>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:
char str[] = "01\n";
if( strchr(str,variable) != 0)
{
    // found it
}
Last edited by Ancient Dragon : Sep 30th, 2007 at 8:17 pm.
Reply With Quote  
Posts: 13
Reputation: megan-smith is an unknown quantity at this point 
Solved Threads: 0
megan-smith megan-smith is offline Offline
Newbie Poster

Re: newline character

  #5  
Oct 1st, 2007
Thanks!
I appreciate it.
Last edited by megan-smith : Oct 1st, 2007 at 12:29 am.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Similar Threads
Other Threads in the C Forum
Views: 4781 | Replies: 4 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 3:35 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC