Thread: array printing

  1. #1
    Musicman - Canora
    Join Date
    Aug 2005
    Location
    Melbourne
    Posts
    252

    array printing

    Hey guys i want to be able to print whatever is inside that array how many times the user inputs. For example user types in 2 i want it to display 2 rows and 2 columns. Or types in 3 i want it to display 3 rows and 3 columns. The array holds '?' up to 16 of them. i sorta done a little bit of it but stuck

    if user selects 3

    ? ? ?
    ? ? ?
    ? ? ?

    if user selects 2
    ? ?
    ? ?


    Code:
    #define MAX_GRID 16
    #define BLANK ''
    #define UNKNOWN '?'
    
    void printGridMineSize(char displayGrid[MAX_GRID][MAX_GRID], unsigned size, int getMineSize)
    {
        int i=0;
        int k=0;
        
        
      
        printf("-------------------\n");
        
        for(i=0; i<size; i++)
        {
        
            for(k=0; k<size; k++)
    	{
    	   
    	  printf("  %c     \n",displayGrid[i][k]); 
    	  
    	  printf(" +---+\n");      
    	
    	}
    	printf("\n");
        
        }
       
    
    }
    
    void init(char minefield[MAX_GRID][MAX_GRID], 
              char displayGrid[MAX_GRID][MAX_GRID])
    {
       int i;
       int j;
    
       for(i=0; i<MAX_GRID; i++)
       {
    
          for(j=0; j<MAX_GRID; j++)
          {
             minefield[i][j] = BLANK;
             displayGrid[i][j] = UNKNOWN;
             
             
          }
    
       }
    
    
    }

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    what are you "stuck" on? It looks ok to me. It may not be a very readable format, but the grid elements should be ok.

  3. #3
    Registered User
    Join Date
    Feb 2006
    Posts
    155
    Code:
    #include<stdio.h>
    #include<stdlib.h>
    
    
    #define MAX_GRID 16
    #define BLANK ''
    #define UNKNOWN '?'
    
    void printGridMineSize(char displayGrid[][MAX_GRID], unsigned size, int getMineSize)
    {
        int i=0;
        int k=0;
        
        
      
        printf("-------------------\n");
        
        for(i=0; i<size; i++)
        {
        
            for(k=0; k<size; k++)
    	{
    	   
    	  printf("  %c     ",displayGrid[i][k]); 
    	  
    	 // printf(" +---+\t");      NOTE
    	
    	}
    	printf("\n");
        
        }
       
    
    }
    
    void init( char minefield[][MAX_GRID], 
              char displayGrid[][MAX_GRID])
    {
       int i;
       int j;
    
       for(i=0; i<MAX_GRID; i++)
       {
    
          for(j=0; j<MAX_GRID; j++)
          {
             minefield[i][j] = BLANK;
             displayGrid[i][j] = UNKNOWN;
             
             
          }
    
       }
    
    
    }
    
    main(){
    char minefield[MAX_GRID][MAX_GRID];
    char displayGrid[MAX_GRID][MAX_GRID];
    init(minefield,displayGrid);
    printGridMineSize(displayGrid,4,2);
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. printing half a char array
    By theoneandonly in forum C Programming
    Replies: 19
    Last Post: 11-11-2006, 07:27 AM
  2. Replies: 3
    Last Post: 11-03-2003, 08:55 PM
  3. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM
  4. Array Program
    By emmx in forum C Programming
    Replies: 3
    Last Post: 08-31-2003, 12:44 AM
  5. Printing an integer stored in an array
    By Freez3L in forum C Programming
    Replies: 4
    Last Post: 11-18-2002, 02:11 AM