What are Carriage Return, Linefeed, and Form Feed?
Carriage return (CR), linefeed (LF), and form feed (FF) are control characters used in text formatting and printing, originating from the early days of computing and typewriters. Here’s what each represents:
Carriage Return (CR)
- Symbol:
\r
- Function: Moves the cursor or print head to the start of the current line without advancing to the next line.
- Modern Use: Historically used in typewriters; in computing, it serves as a line-ending character in systems like classic Mac OS.
Linefeed (LF)
- Symbol:
\n
- Function: Advances the cursor or print head to the next line without returning to the start of the line.
- Modern Use: Common in UNIX-based systems (like Linux and macOS) to indicate the end of a line in text files.
Form Feed (FF)
- Symbol:
\f
- Function: Advances the cursor or print head to the start of the next page or a defined section.
- Modern Use: Rarely used today but may appear in some printer control sequences or specialized text processing.
Key Differences
Character | Symbol | Purpose |
---|---|---|
Carriage Return | \r |
Returns to the beginning of the current line. |
Linefeed | \n |
Moves to the next line. |
Form Feed | \f |
Moves to the start of the next page. |
Combining CR and LF
In Windows systems, both CR and LF (\r\n
) are used together to mark the end of a line. This ensures compatibility with older software and hardware.