Proper way to copy C strings

前端 未结 4 1060
野的像风
野的像风 2020-12-02 00:18

Is there an easy way to copy C strings?

I have const char *stringA, and I want char *stringB to take the value (note that stringB

4条回答
  •  孤街浪徒
    2020-12-02 00:19

    You're probably looking for strncpy, which allows you to copy the first n characters from a string. Just be sure to add the null-terminator at position n of the copied-to string.

提交回复
热议问题