What's the difference between a carriage return and a newline? We usually press the ENTER key is a carriage return or line-related skills

Source: Internet
Author: User
Tags fread
\ n is a line change, English is the LINEFEED,ASCII code is 0xA.
\ r is enter, English is carriage return, ASCII code is 0xD.

If you use a mechanical typewriter, you know the difference between carriage return and line change ...
The line is to roll a cylinder, do not change the horizontal position.
Carriage return is to reset the horizontal position, do not scroll the drum.


But we usually press ENTER in the end is to return or line, not too clear??
See a saying: Windows down enter is \n\r,unix under \n,mac is \ r

In MS's system, the plain text format presses a return key to enter two characters, one for carriage returns and one for line wrapping. In a Linux system, it's just a carriage return.
The above is referred to the discussion of http://topic.csdn.net/t/20040617/23/3101951.html# and http://topic.csdn.net/t/20021113/09/1171659.html

There are also file operations at the time of programming

WB (binary) or WT (text mode) will also have an impact. I did an experiment (with a. net2003)
Enter 12 in the 01.txt file and enter, the binary you see in UltraEdit is 0d 0a

Then the program is as follows:
Copy Code code as follows:

int Mian ()
{FILE *FP1,*FP2,*FP3,*FP4,*FP5,*FP6;

Char a[10];
Char b[10];

FP1 = fopen ("01.txt", "R");
FP3 = fopen ("02.txt", "w");
Fread (a,sizeof (unsigned char), 8,FP1); A is 0a.
Fwrite (a,sizeof (unsigned char), 8,FP3); 02.txt is 0d 0a, the reason is that in the case of input, the change line carriage return to the line, and then the output line will be converted to line return
Fclose (FP1);
Fclose (FP3);

FP2 = fopen ("01.txt", "RB");
FP4 = fopen ("03.txt", "WB");
Fread (b,sizeof (unsigned char), 8,FP2); B is 0d 0a.
Fwrite (b,sizeof (unsigned char), 8,FP4); 03.txt is 0d 0a, because the binary case of carriage return and line-wrapping (like the text of the conversion) does not exist
Fclose (FP2);
Fclose (FP4);

return 0;
}

It seems like the conclusion is this: Read the way, in the text mode, enter is 0x0a, in the binary mode, enter is 0x0d,0x0a.

MSDN found this: Also, in text mode, carriage return–linefeed combinations are to single translated on input, and L Inefeed characters are translated to carriage return–linefeed on output. (in the case of input, a newline carriage return is converted to a newline, and then the output is changed to a newline return) when a Unicode stream-i/o function operates in text mode (the default), the source or de Stination Stream is assumed to be a sequence of multibyte characters. Therefore, the Unicode stream-input functions convert multibyte characters to wide characters. For the same reason, the Unicode stream-output functions convert wide characters to multibyte characters.

Open in binary (untranslated) mode; Translations involving Carriage-return and linefeed characters are. (The conversion of carriage return and line wrapping is not present in binary case).

One more quote: HTTP://ZHIDAO.BAIDU.COM/QUESTION/27868102.HTML?FR=QRL3

Soft Hard Return}

Hard return is ordinary we press ENTER to produce, it in the line of the same time also plays the role of paragraph separation.
Soft return is generated with SHIFT + Enter, it wraps, but does not change the paragraph, that is, two paragraphs of text in Word belong to the same "paragraph". You'll realize that when you apply a format.


Switch:
Edit--Replace, click Advanced, Manual line break in "Find what" point in "special character", and then click the paragraph mark in "special character" with "Replace with", and then tap Replace All.

There is only one type of enter on the keyboard, but there are two different lines of line marking, not to mention a miracle.

Our usual carriage return is hard return, which is the small curved arrow that is produced by tapping the ENTER key in Word, accounting for two bytes. This kind of carriage return can effectively make the paragraph mark out to separate clearly. The text from two hard returns is a paragraph, and you can set paragraph marks on it individually without worrying about other paragraphs being affected. This is also our habit of using hard return reason: typesetting convenient.

But hard return also brought trouble to us. If you are a web designer, or a forum Ranger, there must be such an experience: when you are going to change lines, the line is really not compliment, the line spacing is too big! In fact, this and hard return principle is the same, but in Word and other text editor does not show its "true". But this kind of typesetting does cause a little difficulty, at this time we have to please a hard return brother: Soft return.

Soft return takes up only one byte and is a downward arrow in Word. If you copy text to Word from a very complex web page, you will never be unfamiliar with it. But it's not easy to enter a soft return directly in Word. Because soft return is not a true paragraph mark, it is only a single line, not a fragment. So it's not very good for text typesetting because it can't be given a special format as a separate paragraph. But still, it has a pivotal position in web design.

Soft return can make the line spacing between the two lines significantly smaller because it is not a paragraph mark and is distinguished from the mandatory paragraph mark-hard return. The HTML code for hard return is &LT;P&GT. </p&gt, the paragraph content is sandwiched inside, and the soft return code is very lean:<br>. So in the Web page want to use soft return, just switch to the code page, type the soft return code.
Let me talk about the conversion of carriage returns when different editor text is copied to each other.

The Earth people all know that the text of the Web page if copied to Word, the hard return turns into a curved arrow, and the soft carriage return changes to a downward arrow. As a result, a friend who is accustomed to editing text in Word is not accustomed to uncomfortable situations.

It's also true that text in Word is copied to a Web page. It can be said that Word and Web pages are more compatible, or how to "save as a Web page" this option?

Notepad is also the more people touch the editor. But in recent years, with the development of society and the various drawbacks of Notepad, many people put it in the doghouse. I can only express regret, because the notepad itself is not rich in the function of other editors can not replace the advantages. When you copy the page again, you might as well paste it into Notepad and try it. Haha, no matter what the Web designer used to enter the car, now become a carriage return! What, you don't believe me? Then look at it: soft return into the ordinary carriage return, hard return into two ordinary return. You can copy text from Notepad to Word, and the carriage return in Notepad is all turned into a hard return! You can again copy text from Notepad to the Web editor, all enter into a soft return!!

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.