Escape all special characters in printf()

前端 未结 4 1569
遇见更好的自我
遇见更好的自我 2020-12-07 04:24

Is there an easy way to escape all special characters in the printf() function?

The reason why I would like to know how to do this is because I am print

4条回答
  •  -上瘾入骨i
    2020-12-07 05:02

    Use the isprint library function to determine if the character is printable:

    #include 
    ...
    if (isprint(data[i]))
      printf(" %c", data[i]);    // prints character
    else
      printf(" %d", data[i]);    // prints code value for character
    

提交回复
热议问题