null terminating a string

前端 未结 4 737
有刺的猬
有刺的猬 2020-11-29 05:48

gcc 4.4.4 c89

What is the standard way to null terminate a string? When I use the NULL I get a warning message.

*dest++ = 0; 
*dest++ =          


        
4条回答
  •  一整个雨季
    2020-11-29 06:18

    '\0' is the way to go. It's a character, which is what's wanted in a string and has the null value.

    When we say null terminated string in C/C++, it really means 'zero terminated string'. The NULL macro isn't intended for use in terminating strings.

提交回复
热议问题