Get the carriage return 0d and wrap 0a.

Source: Internet
Author: User
Tags sleep
What are 0x0d and 0x0a
, it's possible that most people know it's a carriage return and a newline character, but that's a carriage return, which is a newline. It is estimated that a lot of people are not clear for a moment---
Perhaps you do not believe, then the investigation of the colleagues around, the estimate will contain the following words "probably." I remember. Carriage return is 0x0d. " This time I transplant arm-linux C program, to VC + +,
Found a lot of different, especially this carriage return line waste my morning time, I decided to take this opportunity to completely finish them,
These two annoying guys. Let's talk about the thing that's been wasting my morning----
The lesson is very important, I hope you do not repeat my mistakes----, under Arm-linux, write binary files, open the file when you write it
With a fp_wthdisk = fopen (File_pathname, "w");
The format can be written on it. After porting this program to VC + +, I found that once I write to the file 0x0a, the front will automatically add 0x0d
, I thought it was the problem I wrote to the array, and I didn't find anything wrong with it, and then my colleague asked me: "You're not writing in binary format." "I said:
"Yes, fwrite w format, no problem ah", then he said, you try "WB format write"
, after the WB, really good, severe. , I gave him a thumbs up.
See here, the above prompted me to make up my mind to make sure that the reason for the return line is finished. I think someone might make the same mistake.
But if you know the following questions, you don't have to waste your time and keep watching. 1. Under Windows XP Visual C + +, press ENTER, the system gets the character is 0x0d
Or 0x0a, or 0x0d and 0x0a.
2.
The function of a carriage return (0x0d) is to return to the line's beginning position, indicating that it has been entered, remains in the last position, or the cursor moves to the starting position of the next row.
1. The answer is only to get the characters
0x0d 2.
The answer is to move the cursor to the beginning of the line. Note: Carriage return and line wrapping have different meanings in different environments, just as sleep (1) and sleep (1
"Note that the two functions are different, sleep (1) in Linux to indicate the delay of 1s, while sleep (1) in VC + + table
Indication Delay 1ms
, if not according to the environment to discuss carriage return and line change, is meaningless, can only let people go astray and waste time.
I'm only in Arm-linux C and VC
Under the test, please everyone in contact with other language environment, to promote carefully, do not do their own experiments, the most reliable. In Arm-linux C and VC + + the meaning of the next car line is as follows.
Carriage return Code: CR ASCII code: \ r, Hex, 0x0d
, the function of a carriage return is simply to move the cursor to the starting position of the line;
NewLine code: LF ASCII code: \ n, Hex, 0x0a, line to the beginning of the next line start;
Linux and Windows, carriage return test
CODE:
sprintf (Versionbuf, "%s", "test_version_1_0_11\rabcdefg\r34567\n"); printf ("%s", versionbuf);
Print output: 34567fgrsion_1_0_11, the above conclusion is proved.
In fact, the reason for getting in and out of the line is to confuse everyone with the keyboard
"Enter", 0x0d says "carriage return", we are in Windows
Under the TXT file under the hit enter and so on the situation stirred together. Hit the ENTER key on the keyboard, the word Fu Da is different under different software.
Under Windows in
TXT file in the hit enter, and then 16 into the system observation, you will find 2 characters, 0x0d and 0x0a, this everyone knows, but this does not mean that in any case, hit enter, will get 0x0d and 0x0a. Under Linux, when you hit enter on a file, you'll find that it only adds one character at a time.

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.