Complete 0x0d and 0x0a

Source: Internet
Author: User
Complete 0x0d and 0x0a-Linux general technology-Linux programming and kernel information. The following is a detailed description. What are 0x0d and 0x0a? Most people may know that they are carriage return and line feed characters, but that is carriage return and that is line feed? It is estimated that many people cannot make it clear at the moment-Maybe you don't believe it, then investigate the colleagues around you. It may include the following words: "probably. I remember. Enter 0x0d ". This time I transplanted the arm-linux C program to VC ++ and found many differences. In particular, this carriage return is a waste of time for me in the morning. I decided to take this opportunity to completely fix them, these two annoying guys.

First, let's talk about the thing that wastes me a morning-the lesson is very important. I hope you will not repeat my mistakes-write binary files in arm-linux, when you open the file, you can write fp_wthdisk = fopen (file_pathname, "w");, in w format. After porting this program to vc ++, I found that once I write 0x0a to the file, the front side will automatically add 0x0d. I thought it was my problem of writing arrays, I did not find any problem after repeated checks. My colleague asked me: "Are you a file written in binary format?" I said, "Yes, there is no problem with fwrite w format." Later, he said, you should try "write in wb format". After changing it to wb, it would be great !, I gave him a thumbs up.

Seeing this, the above prompted me to make up my mind to figure out the reason for the carriage return line break. I think someone may make the same mistake. However, if you are familiar with the following questions, you do not have to waste time to continue reading them.

1. in Windows XP Visual C ++, press the Enter key. Will the system get the characters 0x0d, 0x0a, 0x0d, and 0x0a?

2. When I press enter (0x0d), it returns to the first position of the row, indicating that the row has been input, staying at the last position, or is the cursor moving to the start position of the next row?

1. The answer is to only get the character 0x0d.

2. The answer is: Press enter to move the cursor to the starting position of the row.

Note: Carriage Return and line feed have different meanings in different environments, just as sleep (1) and Sleep (1) [Note S uppercase] functions are different, sleep (1) in linux, the latency is 1 s, and Sleep (1) is 1 ms in vc ++. it is meaningless to discuss carriage return and line feed based on the environment, it can only make people go astray and waste time.

I have only conducted tests in arm-linux C and vc ++. Please be careful when you are in touch with other language Environments. If you cannot, you can do the tests by yourself, which is the most reliable. In arm-linux C and vc ++, press enter to wrap the line as follows.

Press Enter code: cr ascii code: \ r, hexadecimal, 0x0d. Press enter to move the cursor to the starting position of the row;

Line feed code: lf ascii code: \ n, hexadecimal, 0x0a, line feed to the start position of the next line;

In Linux and windows, press enter to test
CODE: sprintf (versionbuf, "% s", "TEST_VERSION_1_0_11 \ rabcdefg \ r34567 \ n ");
Printf ("% s", versionbuf );
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.