clearing a char array c

后端 未结 16 818
挽巷
挽巷 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 10:59

    You should use memset. Setting just the first element won't work, you need to set all elements - if not, how could you set only the first element to 0?

提交回复
热议问题