printing double array

Discussion in 'C' started by musicmancanora4, Mar 28, 2006.

  1. musicmancanora4

    musicmancanora4 New Member

    Joined:
    Mar 9, 2006
    Messages:
    42
    Likes Received:
    0
    Trophy Points:
    0
    Hi guys inside the double array it holds '?' character.

    How would i do the format printing to print it like this

    ithe user input variable is the size variable
    if 5 is typed in it suppose to print 5 rows and columns and print 2 rows and columns if i entered 2.

    for example
    user inputs 2


    +---+---+
    | '?' | '?' |
    +---+---+
    | '?' | '?' |
    +---+---+

    it has to print the grid like this and im havin trouble with the formatting


    Code:
    void printGridMineSize(char displayGrid[MAX_GRID][MAX_GRID], unsigned size, int getMineSize)
    {
        int i=0;
        int k=0;
        int j=0;
        
      
        printf("-------------------\n");
        
        for(i=0; i<size; i++)
        {
            
            for(k=0; k<size; k++)
    	{
    	  
    	  printf("%c",displayGrid[i][k]); 
    	  
    	 
    	  
    	 
    	}
    	/*printf("  %c     \n",displayGrid[i][k]); */
    	  
    	printf("\n");
       
        }
        
        for(j=0; j<size; j++)
        {
        printf("+---+");
        }
        printf("\n");
    }
    
    
    
     
    Last edited: Mar 28, 2006
  2. coderzone

    coderzone Super Moderator

    Joined:
    Jul 25, 2004
    Messages:
    736
    Likes Received:
    38
    Trophy Points:
    28
    Here is the solution for your prob

    Code:
    for(int i=0; i < size; i++)
    {
    	for(int j=0; j < size; j++)
    	{
    		printf("+");
    		printf("---");
    	}
    	printf("+\n");
    	for(j=0; j < size; j++)
    	{
    		printf("| ");
    		printf("? ");
    	}
    	printf("|\n");
    	for(j=0; j < size; j++)
    	{
    		printf("+");
    		printf("---");
    	}
    	printf("+\n");
    }
     
  3. musicmancanora4

    musicmancanora4 New Member

    Joined:
    Mar 9, 2006
    Messages:
    42
    Likes Received:
    0
    Trophy Points:
    0
    thnxs buddy i got it
     
  4. coderzone

    coderzone Super Moderator

    Joined:
    Jul 25, 2004
    Messages:
    736
    Likes Received:
    38
    Trophy Points:
    28
    My pleasure
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice