08
2020
12

memset()函数--------c语言


 void *memset(void *str, int c, size_t n) 复制字符 c(一个无符号字符)到参数 str 所指向的字符串的前 n 个字符。


原型:void *memset(void *str, int c, size_t n)
#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)

微信扫码关注

更新实时通知

« 上一篇 下一篇 »

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。