943,972 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 3801
  • C RSS
Mar 28th, 2006
0

printing double array formatting trouble

Expand Post »
Hi guys inside the double array it holds '?' character.

How would i do the format printing to print it like this

ithe user input variable is the size variable
if 5 is typed in it suppose to print 5 rows and columns and print 2 rows and columns if i entered 2.

for example
user inputs 2


+---+---+
| '?' | '?' |
+---+---+
| '?' | '?'|
+---+---+

it has to print the grid like this and im havin trouble with the formatting



  1. void printGridMineSize(char displayGrid[MAX_GRID][MAX_GRID], unsigned size, int getMineSize)
  2. {
  3. int i=0;
  4. int k=0;
  5. int j=0;
  6.  
  7.  
  8. printf("-------------------\n");
  9.  
  10. for(i=0; i<size; i++)
  11. {
  12.  
  13. for(k=0; k<size; k++)
  14. {
  15.  
  16. printf("%c",displayGrid[i][k]);
  17.  
  18.  
  19.  
  20.  
  21. }
  22. /*printf(" %c \n",displayGrid[i][k]); */
  23.  
  24. printf("\n");
  25.  
  26. }
  27.  
  28. for(j=0; j<size; j++)
  29. {
  30. printf("+---+");
  31. }
  32. printf("\n");
  33. }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
musicmancanora4 is offline Offline
34 posts
since Mar 2006
Mar 28th, 2006
0

Re: printing double array formatting trouble

Buffer size is too much , reduce it
Reputation Points: 13
Solved Threads: 2
Junior Poster
Vinoth is offline Offline
125 posts
since Jun 2004
Mar 28th, 2006
0

Re: printing double array formatting trouble

>it has to print the grid like this and im havin trouble with the formatting
Do you need to print the grid as well as the array contents? If so, it takes a smidge more work.
  1. for ( i = 0; i < limit; i++ ) {
  2. /* Print a grid line */
  3. for ( j = 0; j < limit; j++ )
  4. printf ( "+---" );
  5. printf ( "+\n|" );
  6.  
  7. /* Print the row */
  8. for ( j = 0; j < limit; j++ )
  9. printf ( "'%c'|", grid[i][j] );
  10. putchar ( '\n' );
  11. }
  12.  
  13. /* Print the last grid line */
  14. for ( j = 0; j < limit; j++ )
  15. printf ( "+---" );
  16. printf ( "+\n|" );
>Buffer size is too much , reduce it
That's a rather useless comment. Elaborate, or don't bother posting.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004

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: everything abt container classes
Next Thread in C Forum Timeline: i can't seem to make my search function work.... help!...





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


Follow us on Twitter


© 2011 DaniWeb® LLC