티스토리 뷰

프로그래밍/C, C++

통신문자 구분 표시

Dev-Drake 2019. 6. 28. 10:24
반응형

const char *CommCode[] = {
    "NUL","SOH","STX","ETX","EOT",
    "ENQ","ACK","BEL","BS ","TAB",
    "LF ","VT ","FF ","CR ","SO ",
    "SI ","DLE","DC1","DC2","DC3",
    "DC4","NAK","SYN","ETB","CAN",
    "EM ","SUB","ESC","FS ","GS ",
    "RS ","US "
};

 

void CommDisplay(unsigned char *str, int len)
{
  int   i;
 char  bf[2000];
 unsigned int cnt = 0;

 memset(bf, 0, sizeof(bf));

  for (i = 0; i < len; i++) {
      if (str[i] >= 0x20)  {
       bf[cnt ++] = str[i];
      }
      else {
       bf[cnt ++] = '[';
       memcpy(&bf[cnt], CommCode[str[i]], 3); cnt += 3;
       bf[cnt ++] = ']';
      }

      if (cnt > sizeof(bf) - 5) break;
  }

  printf("(%d)%s", len, bf);
}

 

반응형
댓글
반응형
최근에 올라온 글
Total
Today
Yesterday