objective c and arrays

Discussion in 'Mac Programming' started by kashmoney2006, Mar 25, 2008.

  1. macrumors regular

    Joined:
    Dec 12, 2007
    Messages:
    233
    #1
    I am trying to create a tic tac toe program in xcode using objective c in an attempt to learn the language. i was wondering if objective c supports 2-D arrays? that is hove i implemented it in previous languanges but cant figure it out in ObjC. in c++ i used something similar to

    Code:
     int board[][] 
    is this possible in ObjC?
     
  2. macrumors 68000

    Joined:
    Feb 23, 2006
    Messages:
    1,642
    #2
    It's standard C syntax. If you want to get fancy I think the NSArray class would be your other option.
     
  3. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Messages:
    3,172
    Location:
    Dallas, TX
    #3
    NSMutableArray is an object. You can make an NSArray or NSMutableArray of them, if you want to. Those can be arrays of NSNumbers that you store something in. I wouldn't, though.

    I don't know what you want to store, exactly, but I think a single dimension array should suffice for this purpose. If you are having a 3x3 array to store board state, i'd say just use a 9 element array. I'd say just have them be chars. Ints are SO big, after all. You can save *27* bytes assuming 32 bit ints. Then you can store 'X','O', or ' '(or '\0' if you prefer).

    I am, of course, being facetious. If you really want to be a glutton for punishment, you should store the board state in a single short(2-byte) integer.

    -Lee
     
  4. macrumors G5

    gnasher729

    Joined:
    Nov 25, 2005
    Messages:
    14,249
    #4
    int board [][]

    while not work either in C++ or in C or in Objective-C.

    int board [10][10] works in all three languages.
     
  5. macrumors newbie

    Joined:
    Mar 25, 2008
    Messages:
    6
    Location:
    Pakistan
    #5
    Problem with Socket In Objective-c

    hi frndz,
    i wana discusss a problem related my Client/server application.
    while running properly if i terminate my Server application and then restart,my socket remains busy for about 15 to 30 sec..:confused:
    do anyone has any idea?
     
  6. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Messages:
    3,172
    Location:
    Dallas, TX
    #6
    try posting in a new thread, and maybe posting a code snippet.
     
  7. macrumors newbie

    Joined:
    Mar 25, 2008
    Messages:
    6
    Location:
    Pakistan
    #7
    SORRY, Actually am a beginner and its my 1st...nw i'll tack care....
     
  8. macrumors newbie

    Joined:
    Mar 25, 2008
    Messages:
    6
    Location:
    Pakistan
    #8
    ok thanks

    SORRY, Actually am a beginner and its my 1st post...nw i'll tack care....
     

Share This Page