Just started programming in Objective-C yesterday with a Java background and I am lost. I have a program that works, and it's purpose is to take in the name, age, and weight of a person from the console and then output those values back to the user. My problem is when I type the data into the console it will only show me the first letter that I type in. Then it will not show me any other characters of my string. So here is some sample console data to demonstrate my point.
Console:
2012-11-14 17:56:05.673 Tutorial[1757:403] Please Enter In Your Name
warning: this program uses gets(), which is unsafe.
C
2012-11-14 17:56:09.494 Tutorial[1757:403] Please Enter Your Age
1
2012-11-14 17:56:11.239 Tutorial[1757:403] Please Enter Your Weight
2
2012-11-14 17:56:13.205 Tutorial[1757:403]
Name: Chris
Age: 18
Weight: 200
As you can see it will only show me the first letter of what I type but it actually uses the enter string. Why on earth is this happening?
Function Declarations:
#import "Person.h"
Person * readPersonData (Person * object);
void writePersonInformation(Person * object);
Main Method:
int main (int argc, const char * argv[])
{
@autoreleasepool
{
Person * p1 = [[Person alloc] init];
p1 = readPersonData(p1);
writePersonInformation(p1);
}
}
Function Implementations:
Person * readPersonData (Person * object)
{
char nameCharacters[100];
NSString * objectName;
int objectAge, objectWeight;
NSLog(@"Please Enter In Your Name");
gets(nameCharacters);
objectName = [[NSString alloc] initWithUTF8String:nameCharacters];
[object setName : objectName];
NSLog(@"Please Enter Your Age");
scanf("%i", &objectAge);
[object setAge : objectAge];
NSLog(@"Please Enter Your Weight");
scanf("%i", &objectWeight);
[object setWeight : objectWeight];
return object;
}
void writePersonInformation(Person * object)
{
NSLog(@"\nName: %@ \nAge: %i \nWeight: %i", object.getName, object.getAge, object.getWeight);
}