Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

kashmoney2006

macrumors regular
Original poster
Dec 12, 2007
232
0
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?
 
It's standard C syntax. If you want to get fancy I think the NSArray class would be your other option.
 
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
 
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?

int board [][]

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

int board [10][10] works in all three languages.
 
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?
 
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?

try posting in a new thread, and maybe posting a code snippet.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.