Hello everyone! I've programmed for a while in Java and .Net, but never really used C or Objective C. I'm still trying to understand a few concepts. I was working on a simple program just to see how I can make an array of structures. Which I believe I got right. I'm having a hard time figuring out how to access the subclasses and store values to the subclasses I created.
I'm guessing I'm getting the error because of my use of scanf. Can anyone offer any help?
Here's what I have so far.
#import <Foundation/Foundation.h>
//Player Prototype: Stores name and wins so far. It can also print out the name and wins
@interface Player : NSObject
{
NSString *name; //Player name
NSInteger wins; //Player wins
NSInteger losses; //Player losses
NSInteger bp; //extra value for anything I might need in the future.
}
@property (retain, nonatomic) NSString *name;
@property NSInteger wins;
@property NSInteger losses;
@property NSInteger bp;
@end
//Next part
@implementation Player
@synthesize name;
@synthesize wins;
@synthesize losses;
@synthesize bp;
@end
//Brackets
@interface Bracket : NSObject
{
NSMutableArray *playerarray;
Player *addplayer;
}
@property (retain, nonatomic) NSMutableArray *playerarray;//array of players
@property (retain, nonatomic) Player *addplayer;//player and data
-(void) SetUp;
@end
//Starting Bracket, working with only 8. Later moving up to 32
@implementation Bracket
@synthesize playerarray;
@synthesize addplayer;
-(void) SetUp;//sets up the array
{
int i;//counting fun!
playerarray = [[NSMutableArray alloc] init];//initialize a bracket
for(i = 0; i < 8; i++)//To add the players
{
Player *addplayerx = [Player new];//New instance of Player
NSString *p;//Not sure if I need two of them.
NSString *tempname = @"bye";
NSLog(@"Player %d Name:", i);
scanf("%s",&p);
tempname = p;
NSLog(@"%s", tempname);
addplayerx.name = p;
NSLog(@"%s", addplayerx.name);
addplayerx.wins = 0;
addplayerx.losses = 0;
addplayerx.bp = 0;
[playerarray addObject: addplayerx];
[addplayerx release];
[p release];
}
}
@end
//End function
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
Bracket *starting = [Bracket new];
[starting SetUp];
[pool drain];
return 0;
}