string array with garbage character at end

前端 未结 7 2138
遇见更好的自我
遇见更好的自我 2020-11-29 11:29

I have a char array buffer that I am using to store characters that the user will input one by one. My code below works but has a few glitches that I can\'t figure out:

7条回答
  •  甜味超标
    2020-11-29 11:52

    You have to end the string with a \0 character. That's why they are called zero terminated strings.

    It is also wise to allocate 1 extra char to hold the \0.

提交回复
热议问题