943,547 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Marked Solved
  • Views: 6292
  • C RSS
Jul 8th, 2008
0

Passing a pointer to an array.

Expand Post »
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. }
Reputation Points: 10
Solved Threads: 0
Newbie Poster
java_girl is offline Offline
6 posts
since Jul 2008
Jul 8th, 2008
0

Re: Passing a pointer to an array.

Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: assigning a char pointer to a struct member of similar type ........
Next Thread in C Forum Timeline: our very own OS





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC