memset函数

函数原型:extern void *memset(void *buffer, int c, int count)

参数说明:buffer为源字符串,c为要初始化的字符的值,count为初始化buffer中字符的个数。
        
所在库名:#include <string.h>
  
函数功能:把buffer所指内存区域的前count个字节设置成字符c。
  
返回说明:返回void*类型指针。

其它说明:通常可以用它来初始化数组的信息,这样使用很方便。

实例:

    #include<string.h>
    #include
<stdio.h>
    
int main()
    
{
        
char str[100]="Hello,I am sky2098,I liking programing!";
        
char character='H' ;  //指定一个字符
        void *voidtemp;
        printf(
"Before Setting the str is:   %s ! ",str);
        voidtemp
=memset(str,character,strlen("Hello,I am sky2098"));
        
if(voidtemp!=NULL)
        
{
            printf(
"Set Success! ");
            printf(
"After Setting the str is:   %s ! ",str);
        }

        
else
        
{
            printf(
"Set Failure! ");
            printf(
"After Setting the str is:   %s ! ",str);

        }

        
return 0;
    }

在VC++ 6.0  编译运行:

原文地址:https://www.cnblogs.com/lgh1992314/p/5835360.html