Thread: Two dimension Array

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    1

    Two dimension Array

    Hello everybody:
    Ive got a problem. Im working on a 15*15 array which is full of Xes spaces and one O. It looks, only bigger, like this:

    XX XXXXX
    XX XXXXX
    XX XXXXX
    XXO XXXX
    XXX XXXX
    XXX
    XXXXXXXX


    I need to make a function in order to specify where is letter O possitioned. For example in this case (2,3). It would be great if the function could state that letter O is in position (X,Y)

    any ideas on how to solve my problem
    please

    JIMIEXE

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    >any ideas on how to solve my problem

    Loop, compare.
    Code:
    #include <stdio.h>
    
    int foo(const char array[15][15], int *x, int *y)
    {
       int i,j;
       for ( i = 0; i < 15; ++i )
       {
          for ( j = 0; j < 15; ++j )
          {
             if ( array[i][j] == 'O' )
             {
                *x = j;
                *y = i;
                return 1;
             }
          }
       }
       return 0;
    }
    
    int main(void)
    {
       char array[15][15]/* = { your data }*/;
       int i,j;
       if ( foo(array, &i, &j) )
       {
          printf("'O' is at %d,%d\n", i, j);
       }
       return 0;
    }
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating double dimension array.
    By apacz in forum C++ Programming
    Replies: 4
    Last Post: 05-23-2005, 12:39 PM
  2. Type and nontype parameters w/overloading
    By Mr_LJ in forum C++ Programming
    Replies: 3
    Last Post: 01-02-2004, 01:01 AM
  3. 2 dimension string array
    By djarian in forum C Programming
    Replies: 4
    Last Post: 05-05-2003, 12:47 AM
  4. two dimensional dynamic array?
    By ichijoji in forum C++ Programming
    Replies: 6
    Last Post: 04-14-2003, 04:27 PM
  5. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM