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" );
   }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.