View Full Version : objective c and arrays
kashmoney2006
Mar 25, 2008, 04:21 PM
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
int board[][]
is this possible in ObjC?
SC68Cal
Mar 25, 2008, 04:24 PM
It's standard C syntax. If you want to get fancy I think the NSArray class would be your other option.
lee1210
Mar 25, 2008, 06:41 PM
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
gnasher729
Mar 25, 2008, 08:16 PM
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
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.
Shahmeer
Mar 25, 2008, 10:48 PM
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?
lee1210
Mar 25, 2008, 10:57 PM
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.
Shahmeer
Mar 25, 2008, 11:45 PM
SORRY, Actually am a beginner and its my 1st...nw i'll tack care....
Shahmeer
Mar 25, 2008, 11:46 PM
SORRY, Actually am a beginner and its my 1st post...nw i'll tack care....
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.