Programme finishing on exit code -1


#1

hey guys,

bizarre one this… can anyone tell me why my program is finishing on exit code -1:

#include <stdio.h>
#include <math.h>

int main(int argc, const char * argv[])
{
    double pi = 3.14;
    double integerPart;
    double fractionPart;
    
    //pass the address of integerPart as an argument
    fractionPart = modf(pi, &integerPart);
    
    //Find the value stored in integerPart
    printf("integerPart = %.0f, fractionPart = %.2f\n", integerPart, fractionPart);
    
    
    double trouble = 8.43827;
    double firstNumber;
    double afterDecimal;
    
    //pass address of the decimal as an argument
    afterDecimal = modf(trouble, &firstNumber);
    
    printf("firstNumber = %.0f, afterDecimal = %.5f\n", firstNumber, afterDecimal);
    
    return 0;
}

result: integerPart = 3, fractionPart = 0.14
firstNumber = 8, afterDecimal = 0.43827
Program ended with exit code: -1


#2

Kev,

Looks like your compiler is stuck. I copied and pasted your code, as supplied, into a new project and it worked expected (with an exit code of 0).

Sometimes if you edit, reedit, run into precompiler errors, edit some more, run and run a project things just don’t get cleaned up between runs as completely as they should.

When this happens just go to your menu, select Product -> Clean, then build and run your project. 9/10 this fixes the issue. If not, try cutting the code out, pasting into a simple text editor (I use TextWrangler) then cut it back out and paste it into your project. Odd, I know, but these steps have helped me clean out the cobwebs too many times.

Best,

Mark H