C Tutorial/printf scanf/printf Escape Sequence

Материал из C\C++ эксперт
Перейти к: навигация, поиск

\a: Produces a beep or flash; the cursor position is not changed.

<source lang="cpp">#include <stdio.h> main() {

   printf("\a %d", 25);
   printf("AAA");

}</source>

25AAA

\b: Moves the cursor to the last column of the previous line.

<source lang="cpp">#include <stdio.h> main() {

   printf("\b %d", 25);
   printf("AAA");

}</source>

25AAA

Escape Sequence

Escape sequences are the special directives used to format printing.

For example, \n indicates that the next printing should start from the first column of the next line.

4.11.printf Escape Sequence 4.11.1. Escape Sequence 4.11.2. <A href="/Tutorial/C/0080__printf-scanf/aProducesabeeporflashthecursorpositionisnotchanged.htm">\a: Produces a beep or flash; the cursor position is not changed.</a> 4.11.3. <A href="/Tutorial/C/0080__printf-scanf/bMovesthecursortothelastcolumnofthepreviousline.htm">\b: Moves the cursor to the last column of the previous line.</a> 4.11.4. <A href="/Tutorial/C/0080__printf-scanf/fMovesthecursortostartofnextpage.htm">\f: Moves the cursor to start of next page.</a> 4.11.5. <A href="/Tutorial/C/0080__printf-scanf/nNewline.htm">\n: New line</a> 4.11.6. <A href="/Tutorial/C/0080__printf-scanf/rCarriageReturnMovesthecursortothefirstcolumnofthecurrentline.htm">\r: Carriage Return (Moves the cursor to the first column of the current line.)</a> 4.11.7. <A href="/Tutorial/C/0080__printf-scanf/tHorizontalTab.htm">\t: Horizontal Tab</a> 4.11.8. <A href="/Tutorial/C/0080__printf-scanf/vVerticalTab.htm">\v: Vertical Tab</a> 4.11.9. <A href="/Tutorial/C/0080__printf-scanf/Printssingle.htm">\\: Prints single \</a> 4.11.10. <A href="/Tutorial/C/0080__printf-scanf/forquotation.htm">\ for quotation</a> 4.11.11. <A href="/Tutorial/C/0080__printf-scanf/Prints.htm">%%: Prints %.</a>

\f: Moves the cursor to start of next page.

<source lang="cpp">#include <stdio.h> main() {

   printf("\f %d", 25);
   printf("AAA");

}</source>

25AAA

\ for quotation

<source lang="cpp">#include <stdio.h> main() {

   printf("\" %d", 25);

}</source>

" 25

\n: New line

<source lang="cpp">#include <stdio.h> main() {

   printf("\n %d", 25);

}</source>

25

%%: Prints %.

<source lang="cpp">#include <stdio.h> main() {

   printf("%d %%", 25);

}</source>

25 %

\\: Prints single \

<source lang="cpp">#include <stdio.h> main() {

   printf("\\ %d", 25);

}</source>

\ 25

\r: Carriage Return (Moves the cursor to the first column of the current line.)

<source lang="cpp">#include <stdio.h> main() {

   printf("\r %d", 25);

}</source>

25

\t: Horizontal Tab

<source lang="cpp">#include <stdio.h> main() {

   printf("\t %d\tA\t", 25);

}</source>

25     A

\v: Vertical Tab

<source lang="cpp">#include <stdio.h> main() {

   printf("\v %d", 25);
   printf("AAA");

}</source>