Encoding maps character data between representations. In C, a character written by the program may become different bytes in a file or on a console; text I/O performs the conversion when supported. The source and execution environments may also use different encodings, so character constants such as 'a' and '\n', and string literals such as "hello:", provide portable representations for the current platform. section 8.4.3 section 8.5
Use these constraints when handling encoded character data in C:
- Represent a newline with '\n' rather than assuming one file-level end-of-line byte sequence; the C library adapts it to the platform. section 8.4.3
- Do not depend on trailing blanks or tabs surviving text output, because text conversion may suppress whitespace preceding an end of line. section 8.4.3
- Use <ctype.h> classifiers and toupper or tolower for character classes and case conversion instead of hard-coding every platform character. section 8.5
- Terminate hexadecimal escapes carefully: a sequence such as "\xdeBruyn" consumes following hexadecimal characters differently from "\xde""Bruyn". section 8.5
Character codes and numeric conversion
The hexatridecimal example converts an input character into a numeric digit: isdigit(a) maps '0' through '9' to 0 through 9, while toupper followed by isupper maps Latin letters to values beginning at 10. The conversion relies on decimal digits being consecutive and on isdigit not being locale-dependent.








