String Concatenation in C

Level 390 keystrokes

Uses strcat to concatenate two strings together.

C code

// Room for 20 chars: "Hello" uses 6 now, and the result needs 12
1char str1[20] = "Hello";
// The text to append; it starts with a space
2char str2[] = " World";
// Copy str2 over the '\0' of str1 and add a new '\0'; str1 must have enough room
3strcat(str1, str2);
// Print Hello World
4printf("%s\n", str1);

Output

Hello World
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this C code and how often they appear.

  • "× 6
  • ;× 4
  • ,× 2
  • (× 2
  • )× 2
  • [× 2
  • ]× 2
  • =× 2
  • \× 1
  • %× 1

More C examples at level 3

← C typing practice