#include <stdio.h>
#include <string.h> // for memcpy() and memmove()
#include <stdlib.h>
#define SIZE 10
//打印数组
void show_array(double ar[],int n)
{
int index = 0;
for (index=0; index<n; index++) {
printf("%9.4f ",ar[index]);//每个数占9个 保留4位小数
if(index%5==4)//每行6个
{
putchar('\n');
}
}
if (index % 5 !=0) {//最后输出的时候换行
putchar('\n');
}
}
//伪随机生成数组
void fill_array(double ar[],int n)
{
for (int index =0; index<n; index++) {
ar[index] = (double)rand()/((double)rand()+0.1);
}
}
int main()
{
double darray[SIZE];
fill_array(darray, SIZE);
double target[SIZE];
puts("original data:");
show_array(darray, SIZE);
puts("memcpy() used:");
//memcpy按照字节进行copy
memcpy(target, darray, SIZE*sizeof(double));
puts("memcpy() result:");
show_array(target, SIZE);
char str[] = "memmove can be very useful......";
memmove (str+20,str+15,11);
puts (str);
return 0;
}
Result: