函数原型: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 编译运行:
本文详细介绍了memset函数的功能和用法,包括其参数说明、所在库名、返回类型等,并通过一个具体的示例展示了如何使用memset来初始化字符串。
122

被折叠的 条评论
为什么被折叠?



