i want to ascii value of '\n',
The C escape code "\n" is usually 10 (decimal), or 0xa (hex). More information in various places - this was the first table I happened to find.
The ASCII line feed character is always 10... but whether "\n" means "ASCII line feed character" or not in your particular C compiler isn't guaranteed.
Note that even when the escape sequence "\n" means ASCII 10, some file writing routines convert "\n" into the platform default line terminator when you're writing the data. That doesn't affect what the data is in memory though.
EDIT: (I've edited the above too, slightly) Paul R points out this section from the Wikipedia newline entry:
The C programming language provides the escape sequences '\n' (newline) and '\r' (carriage return). However, these are not required to be equivalent to the ASCII LF and CR control characters. The C standard only guarantees two things:
- Each of these escape sequences maps to a unique implementation-defined number that can be stored in a single char value.
- When writing a file in text mode, '\n' is transparently translated to the native newline sequence used by the system, which may be longer than one character. When reading in text mode, the native newline sequence is translated back to '\n'. In binary mode no translation is performed, and the internal representation produced by '\n' is output directly.
On Unix platforms, where C originated, the native newline sequence is ASCII LF (0x0A), so '\n' was simply defined to be that value. With the internal and external representation being identical, the translation performed in text mode is a no-op, and text mode and binary mode behave the same. This has caused many programmers who developed their software on Unix systems simply to ignore the distinction completely, resulting in code that is not portable to different platforms.
The value of '\n' is usually 10, which is the ASCII value of the line feed character.
When you're programming it is often a better idea to write what you want to express rather than researching the value offline and then hardcoding it into your program.
Instead of:
if (x == 10) { ... }
Write:
if (x == '\n') { ... }
The advantages of this are:
- People reading your code will understand what you are trying to do without having to research which character has ASCII value 10.
- If on your system that character has another value the code should hopefully still work.
It is 0x0A in HEX, and 10 in decimal.
More details check here : Newline.
You can check it yourself also :
int _tmain(int argc, _TCHAR* argv[])
{
char ch = '\n';
printf("The ACII value of '\\n' is - %d\n", ch);
return 0;
}
#include<stdlib.h>
#include<stdio.h>
int main(int argc,char** argv)
{
int c='\n';
printf("'%c' is %i\n",c,c);
getchar();
return 0;
}
Is it really that hard to run this through gcc?
The ASCII value of \n
is 10. There's no "usually" about it. C does not require the character encoding to be ASCII or an ASCII superset, but if it is ASCII or an ASCII superset (like Latin-1 or UTF-8) then '\n'==10
.