memset ( void * ptr, int value, size_t num ) , 可以讓我們對pointer所指向的一個記憶體空間塞入資料 , 
在memset中主要有三個參數 , 分別是:
  ptr : Pointer to the block of memory to fill.
  value : Value to be set. The value is passed as an int, but the function fills the block of memory using the unsigned char conversion of this value.
  num : Number of bytes to be set to the value.
  for example : 
#include <stdio.h> 
#include <string.h> 
int main () 
char str[] = "almost every programmer should know memset!"
memset (str,'-',6); 
puts (str);
return 0; 
}
 我們可以看到memset幫我們在str所指向的記憶體空間中塞入了6個'-' .
 

 

ref : http://www.cplusplus.com/reference/clibrary/cstring/memset/

arrow
arrow
    全站熱搜

    JerryCheng 發表在 痞客邦 留言(0) 人氣()