CodeWars C Kata - Double Char

Words
35
Reading
1 min
Listen
Play
3y

DESCRIPTION:
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.

Examples (Input -> Output):

  • "String" -> "SSttrriinngg"
  • "Hello World" -> "HHeelllloo WWoorrlldd"
  • "1234!_ " -> "11223344!!__ "
char *double_char (const char *string, char *doubled)
{
  char *writing_head = doubled;
  char *reading_head = string - 1;
  while (*++reading_head) {
    *writing_head++ = *reading_head;
    *writing_head++ = *reading_head;
  }
  *writing_head = '\0';

  return doubled; // return it
}
CodeWars C Kata - Double Char | Ecency