I have the following code, but can’t get it to display the name at all.
If I have scanf("%s", inputBuffer); i get only the first word. It Breaks at the whitespace. So I changed it to scanf("%[\n]", inputBuffer); but still does not work. Any help please…
> int main (int argc, char *argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int number;
double payRate, hours, totalPay;
NSString *name;
char inputBuffer[200];
NSLog (@"Enter the number of entries to be processed: ");
scanf ("%i", &number);
for(int i = 1; i <= number; i++){
NSLog (@"Enter the name:");
scanf("%[\n]", inputBuffer);
name = [[NSString alloc] initWithUTF8String:inputBuffer];
NSLog(@"Name: %@", name);
NSLog(@"Hours:%.2lf", hours);
NSLog(@"Pay Rate:%.2lf",payRate);
NSLog(@"Total Pay:%.2lf", totalPay);
}
This works for me: