大佬们,怎样实现把一个一维数组的全部赋给另一个一维数组的第i个
类似 array1=[2,2,2,2],array2=[2,3,3],array3[3.5],变成array4=[[2,2,2,2],[2,3,3],[3,5]]
程序代码:
#include <stdio.h> #include <string.h> int main(int argc, char *argv[]) { int i, len; char array[4][4] = { {2, 2, 2, 2}, {2, 3, 3, 0}, {3, 5, 0, 0}, {0} }; #define DEF_STACK_OF DEF_STACK_OF char sof[10] = {0xcc}; enum ar{ar1 = 0, ar2, ar3, ar4}; #define ar_sz(_ar) sizeof(array[_ar]) #define ar_le(_ar) strlen(array[_ar]) //memcpy ar1 memcpy(array[ar4], array[ar1], len = ar_sz(ar1)); //strcpy ar2 strcpy(array[ar4] + len, array[ar2]); len += ar_le(ar2); //strcpy ar3 /* write your code here */ for (i = 0; i < len; i++) { printf("array[ar4][%d] = %d, sof[%d] = %d\n", i, array[ar4][i], i, sof[i]); } return 0; }
[此贴子已经被作者于2021-10-5 14:00编辑过]