Hello, this is my first post. I started off learning C++ then moved to Objective-C for iOS development. I have a pretty n00b question. Basically, I want to accept a users input and then store that input as part of an array (NSMutableArray). What would be the best way to go about this?
The code below is what I am currently working on to familiarize myself with Obj-c. It is a very basic program, sorry for the messy code.
The issue I am talking about happens at the very end of the code, the rest is just me having fun with conditional statements.
Code:
#import <stdio.h>
#import <Foundation/NSArray.h>
#import <Foundation/NSString.h>
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSEnumerator.h>
#import "Fraction.h"
#import "Age.h"
#import "Color.h"
int main ( int argc, const char *argv[] ) {
//create a new instance
Fraction *frac = [[Fraction alloc] init];
Fraction *frac2 = [[Fraction alloc] init];
//set the values
[frac setNumerator: 1];
[frac setDenominator: 5];
[frac2 setNumerator: 7];
[frac2 setDenominator: 9];
//print it
printf( "The fraction is: " );
[frac print];
printf( "\n" );
[frac2 print];
printf( "\n" );
//print conditional statement
if ( [frac denominator] == 5 )
{
printf( "Wowza\n" );
}
else
{
printf( "WRONG!!" );
}
//free memory
[frac dealloc];
[frac2 dealloc];
//set the age value
Age *yourAge = [[Age alloc] init];
int b;
//print statement
printf( "What is your age?\n" );
scanf ( "%i", &b );
[yourAge setAgeOfPerson:b];
[yourAge printAge];
[yourAge dealloc];
//array
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
Color *difColor = [[Color alloc] init];
NSMutableArray *newColors = [NSMutableArray array];
newColors = [NSMutableArray arrayWithObjects:@"green", nil];
NSString *yourColor;
printf( "What is your favorite color?\n" );
scanf( "%i", yourColor );
[newColors addObject: &yourColor];
NSLog( @"%@", newColors );
//free memory
[difColor dealloc];
[newColors release];
//drain pool
[pool release];
return 0;
}