Proper way to empty a C-String

前端 未结 6 1828
孤城傲影
孤城傲影 2020-12-04 15:12

I\'ve been working on a project in C that requires me to mess around with strings a lot. Normally, I do program in C++, so this is a bit different than just saying string.e

6条回答
  •  有刺的猬
    2020-12-04 16:13

    If you are trying to clear out a receive buffer for something that receives strings I have found the best way is to use memset as described above. The reason is that no matter how big the next received string is (limited to sizeof buffer of course), it will automatically be an asciiz string if written into a buffer that has been pre-zeroed.

提交回复
热议问题