Lochard avatar

CodeWars C Kata - Double Char

lochard

Published: 11 Jul 2023 › Updated: 11 Jul 2023CodeWars C Kata - Double Char

CodeWars C Kata - Double Char

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
}

Leave CodeWars C Kata - Double Char to:

Written by

Asylum seeker who hopes to be rid of authoritarian and their surveillance.

Read more #programming posts


Best Posts From Lochard

We have not curated any of lochard's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From Lochard