void *memset(void *str, int c, size_t n) 复制字符 c(一个无符号字符)到参数 str 所指向的字符串的前 n 个字符。
原型:void *memset(void *str, int c, size_t n)
C
#include <stdio.h>#include <string.h>
int main (){
char str[50];
strcpy(str,"This is string.h library function"); puts(str);
memset(str,'$',7); puts(str);
return(0);}
让我们编译并运行上面的程序,这将产生以下结果:
This is string.h library function
$$$$$$$ string.h library function
可以用来清除缓冲区(我这里指的缓冲区指的是自己定义的数组buf)

微信扫码关注
更新实时通知