0

Hi.

Objective: Write a program that declares a 12*12 array of characters. Place Xs in every other element. Use a pointer to the array to print the values to the screen in a grid format.

Listed below is my non-functional attempt. Any help would be most appreciated.

Thanks,

Molly

#include <stdio.h>

void display_grid( char** g );

int i, j;

int main( void ) {

   char grid[12][12];
   
   display_grid( &grid[0][0] );
 
   return 0;
}

void display_grid( char** g ) {

   for( i = 0; i < 12; i++ ) {
      for( j = 0; j < 12; j++ ) {
         g[i][j] = 'O';
      }
   }

   for( i = 0; i < 12; i++ ) {
      for( j = 0; j < 12; j++ ) {

         if( j % 2 == 1 ) {
            g[i][j] = 'X';
         }

         printf( " %c ", g[i][j] );
      }

      printf( "\n" );
   }
}
2
Contributors
1
Reply
3
Views
9 Years
Discussion Span
Last Post by Dave Sinkula
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.