Thread: Help printing 4x4 grid

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    22

    Help printing 4x4 grid

    Hi guys, I'm having some trouble printing out a 4x4 grid. A 1x1 grid is supposed to look like this:

    Code:
    +----+
    |    |
    |    |
    |    |
    +----+
    I've come close but I'm not quite there yet.


    Code:
    int main() {
    
    	row_count = 2;
    	col_count = 2;
    	
    	strcpy(row0NoX, "-----+");
    	strcpy(row1NoX, "     |");
    	strcpy(row2NoX, "     |");
    	strcpy(row3NoX, "     |");
    	strcpy(row4NoX, "-----+");
    	
    	for (row = 0; row < row_count; row++) {
    		
    		for (tiny_row = 1; tiny_row < N_ROWS; tiny_row++) {
    
    			printf("%c", row0NoX[strlen(row0NoX)-1]);
    			printf("%c", row1NoX[strlen(row1NoX)-1]);
    			printf("%c", row2NoX[strlen(row2NoX)-1]);
    			printf("%c", row3NoX[strlen(row3NoX)-1]);
    			printf("%c", row4NoX[strlen(row4NoX)-1]);
    			
    			
    			for (col = 0; col < col_count; col++) {
    				
    				switch (board[row][col]) {
    					case 0:
    						switch (tiny_row) {
    							case 1:
    								printf("%s", row0NoX);
    								break;
    							case 2:
    								printf("%s", row1NoX);
    								break;
    							case 3:
    								printf("%s", row2NoX);
    								break;
    							case 4:
    								printf("%s", row3NoX);
    								break;
    							case 5:								
    								printf("%s", row4NoX);
    								break;
    							default:
    								printf("Error");
    								break;
    						}						
    						break;	
    				}				
    			}
    			printf("\n");			
    		}		
    	}	
    	
    	return (0);
    }
    What I'm getting if I set the grid to 2x2 is this:
    Code:
    +|||+-----+-----+
    +|||+     |     |
    +|||+     |     |
    +|||+     |     |
    +|||+-----+-----+
    +|||+-----+-----+
    +|||+     |     |
    +|||+     |     |
    +|||+     |     |
    +|||+-----+-----+
    The problem with this is its not printing the | at the beginning of the grid but +s. Plus, it's also printing out a space between the two grids which might be because of the \n I put in there...
    Last edited by Watabou; 03-09-2011 at 11:31 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Printing an 4x4 grid and storing it in an array?
    By Watabou in forum C Programming
    Replies: 10
    Last Post: 03-02-2011, 03:03 AM
  2. Another hard C problem
    By alexbcg in forum C Programming
    Replies: 12
    Last Post: 11-23-2010, 08:03 AM
  3. 4x4 grid in C
    By amorvisa in forum C Programming
    Replies: 7
    Last Post: 10-17-2007, 11:13 PM
  4. More Windows Trouble
    By samGwilliam in forum Windows Programming
    Replies: 9
    Last Post: 04-12-2005, 10:02 AM
  5. Find a word in a 2d grid
    By The_Kingpin in forum C++ Programming
    Replies: 2
    Last Post: 02-24-2005, 05:38 PM