以前没有用过这个函数,在一个示例中看到,查了一下。
关于函数“memset()”,参考:https://msdn.microsoft.com/en-us/library/aa246471(VS.60).aspx
函数原型:void *memset( void *dest, int c, size_t count );
作用:将缓冲区的内容设为指定的字符。
参数:dest - 指向目标地址的指针;
c - 用来覆盖缓冲区的内容的字符;
count - 指定需要覆盖的长度。
IDE: Code::Blocks
操作系统:Windows 7 x64
1 /* This program uses memset to 2 * set the first four bytes of buffer to "*". 3 */ 4 5 #include <memory.h> 6 #include <stdio.h> 7 8 int main( void ) 9 { 10 char buffer[] = "This is a test of the memset function"; 11 12 printf( "Before: %s \n", buffer ); 13 memset( buffer, ‘*‘, 4 ); 14 printf( "After: %s \n", buffer ); 15 16 return 0; 17 }
运行结果: