• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSScanner reads the correct number but the number isn't added to an array
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSScanner reads the correct number but the number isn't added to an array


  • Subject: NSScanner reads the correct number but the number isn't added to an array
  • From: Philip Riggs <email@hidden>
  • Date: Sun, 14 Dec 2003 10:21:52 -0700

Using the following code:

NSString * numbers = [[NSString alloc] initWithFormat:@"SET {1.1, 2.2,
3.3, 4.4}"];
NSScanner * aScanner = [NSScanner scannerWithString:numbers];
[aScanner setCharactersToBeSkipped: [NSCharacterSet
characterSetWithCharactersInString:@" ,SET{}"]];
NSMutableArray * numberArray = [[NSMutableArray alloc] init];

BOOL success = TRUE;
while (success)
{
double newNumber = 0.0;
if ([aScanner scanDouble:&newNumber])
{
NSLog (@"newNumber = %f", newNumber);
[numberArray addObject:[NSNumber numberWithDouble:newNumber]];
}
else
success = FALSE;
}

int counter;
for (counter = 0; counter < [numberArray count]; counter++)
NSLog(@"Number %d :: %f", counter, [numberArray
objectAtIndex:counter]);

But gives the output:

newNumber = 1.100000
newNumber = 2.200000
newNumber = 3.300000
newNumber = 4.400000
Number 0 :: 0.000000
Number 1 :: 0.000000
Number 2 :: 0.000000
Number 3 :: 0.000000

Why doesn't numberArray add the correct number?

Thanks!
Philip D Riggs
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: NSScanner reads the correct number but the number isn't added to an array
      • From: j o a r <email@hidden>
    • Re: NSScanner reads the correct number but the number isn't added to an array
      • From: mmalcolm crawford <email@hidden>
  • Prev by Date: find out maximum number of objects in memory at once?
  • Next by Date: Re: NSScanner reads the correct number but the number isn't added to an array
  • Previous by thread: Re: find out maximum number of objects in memory at once?
  • Next by thread: Re: NSScanner reads the correct number but the number isn't added to an array
  • Index(es):
    • Date
    • Thread