- #1
Whovian
- 652
- 3
I'm relatively new to Objective C. I know I'm using C strings instead of NSStrings, but I'm more comfortable with them. And I know this is probably a bad example of Object-oriented programming, but this is for the sake of example.
Nothing happens. I'm not completely sure why not, but again, I'm new to Objective C's approach to Object Oriented programming.
Code:
#import <Foundation/Foundation.h>
@interface Greeter : NSObject
{
char* name;
}
-(void) setname : (char*) newname;
-(char*) getname;
-(void) greet;
-(void) ask;
@end
@implementation Greeter
-(void) setname : (char*) newname
{
name = newname;
}
-(char*) getname
{
return name;
}
-(void) greet
{
printf("Hello, %s!\n",name);
}
-(void) ask
{
printf("What's your name?\n");
scanf("%s",name);
}
@end
int main()
{
@autoreleasepool
{
Greeter* me;
[me ask];
[me greet];
}
}
Nothing happens. I'm not completely sure why not, but again, I'm new to Objective C's approach to Object Oriented programming.