1.内存清空和内存复制函数
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void test()
{
char buf[32] = "hello world";
printf("buf = %s\n", buf);
memset(buf, 0, sizeof(buf));
printf("buf = %s\n", buf);
char dst[64] = { 0 };
char src[64] = "hello world";
memcpy(dst, src, sizeof(dst));
printf("buf = %s\n", dst);
int arr[5] = { 1,2,3,4,5 };
memmove(arr + 2, arr + 1, 3 * sizeof(int));
for (int i = 0; i < sizeof(arr)/sizeof(arr[0]); i++)
{
printf(" = %d\n", arr[i]);
}
char str1[32] = "hello\0world";
char str2[32] = "hello\0aaa";
if (strcmp(str1, str2))
{
printf("字符串比较相同\n");
}
else
{
printf("字符串比较不同\n");
}
if (memcmp(str1, str2, sizeof(str1)))
{
printf("内存比较相同\n");
}
else
{
printf("内存比较不同\n");
}
}
int main()
{
test();
system("pause");
return 0;
}