函數功能:
將以ptr作爲起始地址的數據的num個字節設置爲value。函數返回destination指針。
注意:
1、這裏是按照字節來設置的,因此如果對一個數組來賦初值的話,只能賦值0,或者-1(也就是全1)。
2、凡是mem***函數都是void類型,因此要記住使用類型轉換。
3、雖然是按照字符來初始化,但是第二個參數是int變量。程序中要轉化成字符再賦值
void *memset(void *str, int c, unsigned int count)
{
assert(str != NULL);
void *s = str;
while (count --)
{
*(char *) s = (char) c;
s = (char *) s + 1;
}
return str;
}