How to empty a char array?

后端 未结 13 1778
抹茶落季
抹茶落季 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:59

    By "empty an array" if you mean reset to 0, then you can use bzero.

    #include   
    void bzero(void *s, size_t n);  
    

    If you want to fill the array with some other default character then you may use memset function.

    #include   
    void *memset(void *s, int c, size_t n);  
    

提交回复
热议问题