DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C (http://www.daniweb.com/forums/forum118.html)
-   -   newline character (http://www.daniweb.com/forums/thread91241.html)

megan-smith Sep 30th, 2007 6:59 pm
newline character
 
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

Ancient Dragon Sep 30th, 2007 7:09 pm
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.

megan-smith Sep 30th, 2007 8:43 pm
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.

Ancient Dragon Sep 30th, 2007 9:15 pm
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:
char str[] = "01\n";
if( strchr(str,variable) != 0)
{
    // found it
}

megan-smith Oct 1st, 2007 1:28 am
Re: newline character
 
Thanks!
I appreciate it.


All times are GMT -4. The time now is 1:57 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC