Reputation: 103
The following are my functions:
void initialize(char box[NROW][NCOL]){
int x,y;
for(x=0; x<NROW; x++)
for(y=0; y<NCOL; y++)
if (x==0 || x==NROW-1 || y==0 || y==NCOL-1)
box [x][y] = '=';
else{
box[x][y]=' ';
}
}
void display(char box[NROW][NCOL]){
int x,y;
for(x=0; x<NROW; x++){
for(y=0; y<NCOL; y++){
printf(" %c ", box[x][y]);
}
printf("\n");
}
}
void puzp1(char puz1[NROW][NCOL]){
int x,y;
for(x=1; x<NROW-1; x++){
for(y=1; y<=x; y++){
puz1[x][y]='*';
}
}
}
void puzp2(char puz2[NROW][NCOL]){
int b,c;
for(b=1; b<NROW; b++){
for(c=1; c<NROW-b; c++){
if(b!=3 && c!=3 ){
puz2[b][c]='+';
}
}
}
}
The following is my main:
int main(void){
char ar1[NROW][NCOL];
char ar2[NROW][NCOL];
printf("Puzzle Piece 1:\n");
initialize(ar1);
puzp1(ar1);
display(ar1);
printf("Puzzle Piece 2:\n");
initialize(ar2);
puzp2(ar2);
display(ar2);
I realize that there is another thread with a similar question but it does not quite satisfy what I need. What's happening here is that initialize
generates a hollow rectangle, puzp1
and puzp2
decides the content and display
prints the content.
Is it possible for me to print these two 2D arrays side-by-side; if possible, how?
NROW and NCOL are constants.
Thank you.
Upvotes: 0
Views: 1469
Reputation: 17438
Assuming the 2D arrays are the same size, then for each row, you just need to print the row from the first box, followed by some separating text, followed by the row from the second box.
void display2(char box1[NROW][NCOL], char box2[NROW][NCOL]){
int x,y;
for(x=0; x<NROW; x++){
for(y=0; y<NCOL; y++){
printf(" %c ", box1[x][y]);
}
printf(" ");
for(y=0; y<NCOL; y++){
printf(" %c ", box2[x][y]);
}
printf("\n");
}
}
Upvotes: 1