Thread: Help printing 4x4 grid

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    That was the tough one. There's one or two more changes you will have to make, but they should be pretty simple, so I'll leave them up to you.

  2. #2
    Registered User
    Join Date
    Mar 2011
    Posts
    22
    Okay so is this what you mean because I'm still not there yet.

    Code:
    #include <stdio.h>
    #include <string.h>
    
    #define N_ROWS 6
    
    char board[25][25];
    char row0NoX[8];
    char row1NoX[8];
    char row2NoX[8];
    char row3NoX[8];
    char row4NoX[8];
    
    char command[100];
    int input;
    
    int row;
    int col;
    int tiny_row;
    int row_count;
    int col_count;
    
    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++) {
    			
    			
    			for (col = 0; col < col_count; col++) {
    				
    				switch (board[row][col]) {
    					case 0:
    						printf("%c", row0NoX[strlen(row0NoX)-1]);
    						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);
    }
    I included it when col is 0...but do I put others in the tiny row switch loop?

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