Passing a pointer to an array.

Thread Solved

Join Date: Jul 2008
Posts: 6
Reputation: java_girl is an unknown quantity at this point 
Solved Threads: 0
java_girl java_girl is offline Offline
Newbie Poster

Passing a pointer to an array.

 
0
  #1
Jul 8th, 2008
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

  1. #include <stdio.h>
  2.  
  3. void display_grid( char** g );
  4.  
  5. int i, j;
  6.  
  7. int main( void ) {
  8.  
  9. char grid[12][12];
  10.  
  11. display_grid( &grid[0][0] );
  12.  
  13. return 0;
  14. }
  15.  
  16. void display_grid( char** g ) {
  17.  
  18. for( i = 0; i < 12; i++ ) {
  19. for( j = 0; j < 12; j++ ) {
  20. g[i][j] = 'O';
  21. }
  22. }
  23.  
  24. for( i = 0; i < 12; i++ ) {
  25. for( j = 0; j < 12; j++ ) {
  26.  
  27. if( j % 2 == 1 ) {
  28. g[i][j] = 'X';
  29. }
  30.  
  31. printf( " %c ", g[i][j] );
  32. }
  33.  
  34. printf( "\n" );
  35. }
  36. }
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,343
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 237
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Passing a pointer to an array.

 
0
  #2
Jul 8th, 2008
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC