69,371
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#define three 3
void copy_arr2(int (*target)[5],int (*source)[5],int n);
void copy_arr3(int (*target)[5],int (*source)[5],int (*end)[5]);
void put(int (*target)[5],int n);
int main()
{
int source[three][5] =
{
{1, 2, 3, 4, 5},
{6, 7, 8, 9, 10},
{11, 12, 13, 14, 15}
};
int target2[three][5];
int target3[three][5];
copy_arr2(target2,source,three);
printf("\ntarget2= ");
put(target2,three);
copy_arr3(target3,source,source+three);
printf("\ntarget3= ");
put(target3,three);
/*
printf("\ntarget2= ");
put(target2,three);
printf("\ntarget3= ");
put(target3,three);
*/
return 0;
}
void copy_arr2(int (*target)[5],int (*source)[5],int n)
{
int (*s)[5],*v, (*d)[5], *z;
for (s = source, d = target; s < source + n; s++, d++) {
for (v = *s, z = *d; v < *s + 5; v++, z++)
*z = *v;
}
/*
for (u=source; u<source+n; u++,target++)
{
for(v=*u; v<*u+5; v++,*target++)
{
**target = *v;
}
}
*/
}
void copy_arr3(int (*target)[5],int (*source)[5],int (*end)[5])
{
int *v, *d;
while (source < end) {
for (v = *source, d = *target; v < *source+5; v++, d++)
*d = *v;
target++;
source++;
}
/*
for (; source<end; target++,source++)
{
for (; *source<*end; *target++,*source++)
**target = **source;
}
*/
}
void put(int (*target)[5],int n)
{
int u,v;
for (u=0; u<n; u++)
{
for (v=0; v<5; v++)
{
printf("%2d ",target[u][v]);
}
printf("\n");
}
}