알고리즘 7 - Remove First and Last Character

jabae·2021년 10월 4일
0

알고리즘

목록 보기
7/97

Q.

It's pretty straightforward. Your goal is to create a function that removes the first and last characters of a string. You're given one parameter, the original string. You don't have to worry with strings with less than two characters.

A)

char* remove_char(char* dst, const char* src)
{
    int i = 0;
  
    while (src[i + 1] != '\0')
    {
      dst[i] = src[i + 1];
      i++;
    }
    dst[i - 1] = '\0';
    return (dst);
}
profile
it's me!:)

0개의 댓글