How to empty a char array?

后端 未结 13 2058
抹茶落季
抹茶落季 2021-01-29 19:33

Have an array of chars like char members[255]. How can I empty it completely without using a loop?

char members[255];

By \"empty\" I mean that

13条回答
  •  不知归路
    2021-01-29 19:49

    Don't bother trying to zero-out your char array if you are dealing with strings. Below is a simple way to work with the char strings.

    Copy (assign new string):

    strcpy(members, "hello");
    

    Concatenate (add the string):

    strcat(members, " world");
    

    Empty string:

    members[0] = 0;
    

    Simple like that.

提交回复
热议问题