multi-dimensional array

This is a discussion on multi-dimensional array within the C Programming forums, part of the General Programming Boards category; Hello, In this code: Code: /* void main(void) { int i,j; int array[3][3]={' ', '*', ' ', '*', ' ', ...

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    34

    multi-dimensional array

    Hello,
    In this code:
    Code:
    /* void main(void)
           {
              int i,j;
              int array[3][3]={' ', '*', ' ',
                                        '*', ' ', '*',
                                         ' ', '*', ' '};
    
              for(i=0; i<3; i++)
                 {
                     for(j=0; j<3; j++)
                       {
                           printf("%i", array[i][j]);
                       }
                    printf("\n");
                 }
               } */
    I thought that it would print a design such as this;
    *
    * *
    *
    but in comes out this;
    32 43 32
    43 32 43
    32 43 32
    What am i doing wrong? Thanks, Mcorn

  2. #2
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    Change the %i in the printf() function to %c. That should work.

  3. #3
    Registered User
    Join Date
    Jul 2002
    Posts
    34
    Thank you very much! It's amazing how one little piece of code can be overlooked! Once again thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  2. Zero out two dimensional array
    By davo666 in forum C Programming
    Replies: 16
    Last Post: 01-08-2009, 04:28 AM
  3. Replies: 6
    Last Post: 04-26-2004, 10:02 PM
  4. 2d arrays in C
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 04-20-2002, 11:09 AM
  5. Replies: 5
    Last Post: 11-20-2001, 11:48 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21