fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #define MAZE_COLUMNS 3
  5. #define MAZE_ROWS 3
  6. #define MAZEW_COLUMNS 4
  7. #define MAZEE_COLUMNS 4
  8.  
  9. static void transcribeMazeRow(const char* source, size_t srcColumns, char prefix, char* dest, size_t destColumns)
  10. {
  11. dest[0] = prefix;
  12. memcpy(&dest[1], &source[0], srcColumns * sizeof(source[0]));
  13. }
  14.  
  15. int main(int argc, char* argv[])
  16. {
  17. // 3 rows of 3 columns, each is a distinct char. this is not a string.
  18. char maze[MAZE_ROWS][MAZE_COLUMNS] = { { 'a', 's', 'd' }, { 'u', 's', 'd' }, { 'p', 's', 'd' } };
  19.  
  20. // 3 rows of 4 columns, distinct character values, not a string.
  21. char mazeW[MAZE_ROWS][MAZEW_COLUMNS];
  22. char mazeE[MAZE_ROWS][MAZEE_COLUMNS];
  23.  
  24. for (size_t row = 0; row < MAZE_ROWS; ++row) {
  25. transcribeMazeRow(maze[row], MAZE_COLUMNS, 'W', mazeW[row], MAZEW_COLUMNS);
  26. transcribeMazeRow(maze[row], MAZE_COLUMNS, 'E', mazeE[row], MAZEE_COLUMNS);
  27. }
  28.  
  29. // this part is mostly to show the poster the correct way to refer to all elements of each array.
  30. printf("maze: %c%c%c, %c%c%c, %c%c%c\n",
  31. maze[0][0], maze[0][1], maze[0][2],
  32. maze[1][0], maze[1][1], maze[1][2],
  33. maze[2][0], maze[2][1], maze[2][2] );
  34. printf("mazeW: %c%c%c%c, %c%c%c%c, %c%c%c%c\n",
  35. mazeW[0][0], mazeW[0][1], mazeW[0][2], mazeW[0][3],
  36. mazeW[1][0], mazeW[1][1], mazeW[1][2], mazeW[1][3],
  37. mazeW[2][0], mazeW[2][1], mazeW[2][2], mazeW[2][3] );
  38. printf("mazeE: %c%c%c%c, %c%c%c%c, %c%c%c%c\n",
  39. mazeE[0][0], mazeE[0][1], mazeE[0][2], mazeE[0][3],
  40. mazeE[1][0], mazeE[1][1], mazeE[1][2], mazeE[1][3],
  41. mazeE[2][0], mazeE[2][1], mazeE[2][2], mazeE[2][3] );
  42.  
  43. return 0;
  44. }
  45.  
Success #stdin #stdout 0s 2248KB
stdin
Standard input is empty
stdout
maze: asd, usd, psd
mazeW: Wasd, Wusd, Wpsd
mazeE: Easd, Eusd, Epsd