简体   繁体   中英

How can I know in which way newline is represented in my environment?

I want to know in which ASCII characters a newline represented in my environment, How can I check it? when I read it by getchar or scanf and check what the the ASCII number that was read, I get 10. How can I check the sequence that newline is represented in the environment itself?

Those "text-aware" I/O functions will abstract this and do conversions so that '\\n' works.

One way is to create a text file containing a single (empty) line of text, then re-open it in binary mode and inspect the contents. Binary mode will turn off any such translations of course, and expose the raw bytes.

Not sure how you'd do that without touching the file system, but I'm sure it's doable. Most of the time this kind of thing is static, it's always going to be the same for a particular target platform, so it's of course possible to ie add the knowledge at compile-time instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM