String Concatenation in C
Level 4198 keystrokes
Uses strcat in a loop to concatenate multiple strings into one buffer.
C code
// Start with an empty string so strcat has a '\0' to append to1char result[50] = "";// Array of string pointers2char *words[] = {"Hello", " ", "World", "!"};// Loop through each word3for (int i = 0; i < 4; i++) { // strcat appends at the terminating '\0'; result must have room (50 bytes)4 strcat(result, words[i]);5}// Prints Hello World!6printf("Result: %s\n", result);// 5 + 1 + 5 + 1 = 12 characters7printf("Length: %lu\n", strlen(result));Output
Result: Hello World! Length: 12
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.
"× 14;× 7,× 6(× 5)× 5[× 3]× 3=× 3:× 2{× 2