古詩詞大全網 - 成語解釋 - c語言中字符串清空的函數是什麽?

c語言中字符串清空的函數是什麽?

方法1:使用運行庫函數memset():

memset(str, 0, sizeof(str));

方法2:使用Windows API函數ZeroMemory():

ZeroMemory(str, sizeof(str));

但不能用於指針。指針的情況下,必須這樣:

struct mystr {.......} *p;

...

memset(p, 0, sizeof(struct mystr));

或:

ZeroMemory(p, sizeof(struct mystr));