The linefeed operation can be done easily with the printf() function using the linefeed symbol \n consists of two characters, \ (backslash, not to be confused with slash, /) and n, with no blank in between. In C, the two character symbol \n is one of many character escape sequences. The C compiler considers an escape sequence within a string literal as one character (not two). The importance of this will be seen later. The escape sequence \n causes the cursor to move to the next line and will not be displayed on the screen. Any data behind this symbol is written at the beginning of the next line. You can use \n at any location in the string literal. The \n can be at the beginning, in the middle, or at the end of a string. The number of \n can be more than one. For example, in the statement:
printf("\nHow do we\njump\n\ntwo lines? \n");
the program uses the first \n to move the cursor to a newline, displays "How do we" uses the second \n to jump to a new line, prints "jump" uses the next two \n to jump another two lines, prints "two lines?" and uses the last \n to jump one more line.
No comments:
Post a Comment