fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. void swapping(int dim, int size, void* n1, void *n2)
  6. {
  7. int s = dim * size;
  8. char a[s]; //store data, unreadable
  9. memcpy(a, n2, s);
  10. memcpy(n2, n1, s);
  11. memcpy(n1, a, s);
  12. }
  13.  
  14. int main(void) {
  15.  
  16. double t[10][3];
  17. t[1][0] = 123.0000;
  18. t[1][1] = 324.1231;
  19. t[1][2] = 923.9992;
  20.  
  21. swapping(3, sizeof(double), &t[1], &t[2]);
  22.  
  23. for(int i = 0; i < 3; i++){
  24. printf("t1: %f\n", t[1][i]);
  25. printf("t2: %f\n", t[2][i]);
  26. }
  27.  
  28.  
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0s 2156KB
stdin
Standard input is empty
stdout
t1: 0.000000
t2: 123.000000
====.4====
t2: 123.0000
t1: 0.000000
t2: 324.123100
====.4====
t2: 324.1231
t1: -0.000000
t2: 923.999200
====.4====
t2: 923.9992