1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Xcode 4.6 broken?

Discussion in 'Mac Programming' started by Davy.Shalom, Jul 13, 2013.

  1. macrumors 6502

    Davy.Shalom

    #1
    Hey all,
    So I'm just getting in to coding and I've written a couple of calculator apps in C through Xcode. This morning they were compiling and running fine. They were fully functional. Now neither of them will work properly. The first printf("contents etc. etc.") will print out properly, and then after that it's like the program just ends. I deleted Xcode and am currently re-downloading it to see if this solves the problem. However, if this happens again in the future I would like to know what I can do to solve it.

    Any help is appreciated.

    Thanks
     
  2. gnasher729, Jul 13, 2013
    Last edited: Jul 13, 2013

    macrumors G5

    gnasher729

    #2
    Rule #1: It's not your tools fault, it is your fault. You changed your code (maybe the cat jumped on the keyboard and changed your code) and now it doesn't work. Fix your code. Deleting and re-downloading Xcode was a waste of time.

    Rule #2: Turn on all the compiler warnings you can find. This will show you many bugs in your code.

    Rule #1 is meant seriously. If you think something in the universe is working against you, instead of saying: "I made a mistake. What is the mistake? " you'll never get far.
     
  3. macrumors 6502

    Davy.Shalom

    #3
    Ok well I reinstalled it and you're right. Waste of time. Still not working.

    You see I didn't think that Xcode could have suddenly just failed! But to prove to you that there is something wrong, would you mind supplying me with some code that involves a printf/scanf input and a printf output (verified in your version of Xcode)? I'll make a new project and run it, and it will not work.

    Well it's late and maybe I'm just not thinking correctly. I'll revisit this tomorrow.
     
  4. ArtOfWarfare, Jul 13, 2013
    Last edited: Jul 13, 2013

    macrumors 603

    ArtOfWarfare

    #4
    No, that's backwards and requires more effort on our part than helping you than it should.

    You copy and paste your code here, we tell you either:
    A - It works fine when we copy and paste it into our copies of Xcode, meaning that you likely have an odd compiler setting or something - we'll deal with that in the unlikely event it occurs. Or more likely,
    B - The issue with your code.
     
  5. macrumors G5

    gnasher729

    #5
    Go back to Rule #1: You made a mistake. Accept that as a fact. Now the question is: Which mistake did you make?

    The easiest way would be to set a breakpoint on the first line in your main () function and step through your code. Or post your code here.
     
  6. Davy.Shalom, Jul 13, 2013
    Last edited by a moderator: Jul 13, 2013

    macrumors 6502

    Davy.Shalom

    #6
    Well here is my first program. Please keep it mind it isn't elegant or complex, but if you can find my error I'd be very grateful. When I run this code, the output box shows "Enter an integer between 1 and 100:"

    When I enter anything at all, it will just stop there. Please see the attached image.


    Code:
    #include <stdio.h>
    
    int main(void)
    {
    
        //local declarations
        int num;
        int lineCount;
        
        //statements
        printf ("Enter an integer between 1 and 100:" );
        scanf("%d", &num);
        
        //test number
        if (num > 100)
            num = 100;
        
        lineCount = 0;
        while (num > 0)
        {
            if (lineCount < 10)
                lineCount++;
            else {
                printf("\n");
                lineCount = 1;
            
            } // end else
            printf("%4d", num--);
        } // end while
        return 0;
    } //end main
    Image
     

    Attached Files:

  7. macrumors G5

    gnasher729

    #7
    On a Macintosh, the "Return" key and the "Enter" key are different keys and behave differently. Pressing the "Enter" key or Control-C will stop the program. Use the "Return" key on the main keyboard.
     
  8. macrumors 6502

    Davy.Shalom

    #8
    I'm an idiot. I've been using Mac OS since OS 9 and I made that error. Many thanks for the sanity check!
     
  9. macrumors 603

    ArtOfWarfare

    #9
    I have as well, but I never knew this.
     

Share This Page