For the blank characters (spaces, carriage returns (\ r), line breaks (\ n), horizontal tabs (\ t), and vertical tabs (\ V) in the c Standard) understanding of page feed (\ f)

Source: Internet
Author: User

<Ctype. h> in the C standard library indicates a function:

Int isspace (int c );

This function determines whether character C is a blank character.

In the C standard, blank characters include: space (''), form feed ('\ F'), line feed (' \ n'), and carriage return ('\ R ') horizontal tab ('\ t') and vertical tab (' \ V. Below are some of my understandings.

 

Space

I believe everyone knows it very well. It is worth noting that its ASCII code is 0x20, rather than 0x00. 0x00 indicates null ). I am ashamed to think that the space value is 0 when I start C.

Press enter ('\ R ')

When editing a file, we usually press enter to go to the next line for editing. So is "enter" the same thing as "line feed?

Obviously not. Do not be blinded by the keyboard's return key effect. Here, "enter" (return character) is not "enter" (Return key ).

Press enter ('\ R') to return the output to the beginning of the line. The result may overwrite the output of the line. For example:

Puts ("Hello world! \ Rxxx ");

The output on the terminal is:

Xxxlo world!

If you write the preceding string to a file, for example, run:

Char * s = "Hello world! \ Rxxx ";

File * STR = fopen ("t.txt", "R ");

Fwrite (S, 16, 1, STR );

Use the administrative editor to open t.txt. The displayed effect is determined by the open editor.

The VI effect is


Windows notepad


As you can see, VI replaces \ t with ^ m, and notepad does not display this character.

Line feed ('\ n ')

As the name implies, line feed is to go to the next line of output. For example:

Puts ("Hello \ nworld! ");

Output in Terminal

Hello

World!

However, it should be noted that the terminal output can achieve the line feed effect with "\ n", but the line feed effect should be achieved in the text file output in different systems.

In * nix, each line ends with "\ n", "\ n \ r" in windows, and "\ r" in Mac ".

 

Horizontal tab ('\ t ')

I believe everyone is familiar with '\ t. In general, the output display in the terminal and file is equivalent to pressing the tab key on the keyboard. In general, the horizontal tab will occupy 8 columns. The initial position occupied by the horizontal Tab

Set it to 8th * n (the subscript of the first column is 0 ). For example:

Puts ("0123456 \ txx ");

Puts ("0123456t \ txx ");

The output on the terminal is


Vertical tab ('\ V ')

Vertical tabs are not commonly used. It is used to output the characters After '\ V' from the next line, and the START column is one column after the column where the first character is located. For example:

Puts ("01 \ v2345 ");

Output on the terminal


Form feed ('\ F ')

The effect of the page feed in the terminal is equivalent to the clear command in * nix. The terminal clears the entire terminal screen blank before outputting '\ F' and then outputs the content. This is the output string after the clear command.

 

Finally, I want to explain that '\ r'' \ t' \ v'' \ f' is also a control character, which controls the character output mode. They are displayed in the terminal output, but if a text file is written, a text editor (VI or notepad) is usually used) there is no effect on the display of '\ r'' \ v'' \ F.

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.