Algorithm 25 - Fake Binary


Q.


Description:
Given a string of digits, you should replace any digit below 5 with '0' and any digit 5 and above with '1'. Return the resulting string.

A)

#include <string.h>

void fakeBin(const char *digits, char *buffer) 
{
//  for (size_t i = 0; i < strlen(digits); i++)
//  {
//    if (digits[i] >= '0' && digits[i] < '5')
//      buffer[i] = '0';
//    else if (digits[i] >= '5' && digits[i] <= '9')
//      buffer[i] = '1';
//  }
//  buffer[strlen(buffer)] = '\0';
  size_t len = strlen(digits);
  for (size_t i = 0; i < len; i++)
    buffer[i] = (digits[i] >= '5' ? '1' : '0');
  buffer[len] = '\0';
} -> 주석코드는 왜 안됐지? -> buffer len을 재니까 안됐지 ㅋㅋ