clearing a char array c

后端 未结 16 810
挽巷
挽巷 2020-12-07 10:31

I thought by setting the first element to a null would clear the entire contents of a char array.

char my_custom_data[40] = \"Hello!\";
my_custom_data[0] = \         


        
16条回答
  •  失恋的感觉
    2020-12-07 11:05

    Use:

    memset(my_custom_data, 0, sizeof(my_custom_data));
    

    Or:

    memset(my_custom_data, 0, strlen(my_custom_data));
    

提交回复
热议问题