C/C++ Arena

Step 4 of 5

Escape sequences

Inside a string, some characters are special. A " would end the string early, and there's no key for "new line" that you can put between quotes. C solves this with escape sequences: a backslash \ followed by a character, meaning "the next character is not what it looks like".

You write You get
\n new line
\t tab (jump to the next column)
\" a double quote character
\\ a single backslash
#include <stdio.h>

int main(void) {
    printf("Name\tScore\n");
    printf("Ada\t95\n");
    printf("A path: C:\\games\\cs\n");
    printf("He said \"nice shot\"\n");
    return 0;
}
Name	Score
Ada	95
A path: C:\games\cs
He said "nice shot"

Each escape sequence is two characters in your source code but becomes one character in the output. The compiler does the translation.

Common mistakes

Your task

Print this line exactly, including the quotes:

She said "gg" and left

Challenge 2

Print a small table where the columns are separated by a tab. Fill each blank with the escape sequence for a tab.

Player	Kills
Ada	21

Challenge 3

Print this line exactly. It has both double quotes and backslashes, and each one needs its own escape sequence:

Saved to "C:\games\arena\save1.txt"

Previous: Several lines Next: Comments and reading errors