Silver Challenge: Heading


#1

I have a problem with the output of the code. Here’s my implementation of Silver Challenge:-

-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    if (self=[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        locationManager= [[CLLocationManager alloc] init];
        
        [locationManager setDelegate:self];//self is Whereamicontroller. The delegate pointer is of type id<CLLocationManagerDelegate> and is an ivar of CLLocationManager.
        [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
       
        [locationManager setDistanceFilter:50];//setting up distance filter
        double maxDistance;
        NSLog(@"Enter the max distance after which location starts updating ");
        scanf("%lf",&maxDistance);
        
        if (maxDistance==[locationManager distanceFilter]) { //return CLLocationDistance which is typedef to double.
            NSLog(@"Distance Filter= %f",locationManager.distanceFilter);
            [locationManager startUpdatingLocation];
        }
        
        if ([CLLocationManager headingAvailable]) {
            [locationManager startUpdatingHeading];
        }
        else{
            NSLog(@"Compass not available");
        }
        
    }
    return self;
}

Output:
2013-07-02 19:13:08.332 Whereami[406:c07] Enter the max distance after which location starts updating
2013-07-02 19:13:08.334 Whereami[406:c07] Compass not available

In the output, after the compiler executes NSLog(@“Enter the max distance…”) the control seemingly jumps to else block { NSLog(@“Compass not available”);}, hence skipping these lines:

[code] scanf("%lf",&maxDistance);

    if (maxDistance==[locationManager distanceFilter]) { //return CLLocationDistance which is typedef to double.
        NSLog(@"Distance Filter= %f",locationManager.distanceFilter);
        [locationManager startUpdatingLocation];
    }

[/code]
Whats up with that?
This is highly confusing. The control is skipping these instructions. How is it possible? :frowning: