Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Davy.Shalom

macrumors 6502
Original poster
Dec 23, 2008
465
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
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,565
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

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.
 
Last edited:

Davy.Shalom

macrumors 6502
Original poster
Dec 23, 2008
465
1
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.

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.
 

ArtOfWarfare

macrumors G3
Nov 26, 2007
9,560
6,059
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.

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.
 
Last edited:

gnasher729

Suspended
Nov 25, 2005
17,980
5,565
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.

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.
 

Davy.Shalom

macrumors 6502
Original poster
Dec 23, 2008
465
1
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
 

Attachments

  • Screen Shot 2013-07-13 at 10.04.26 AM.png
    Screen Shot 2013-07-13 at 10.04.26 AM.png
    245.7 KB · Views: 113
Last edited by a moderator:

gnasher729

Suspended
Nov 25, 2005
17,980
5,565
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.
 

Davy.Shalom

macrumors 6502
Original poster
Dec 23, 2008
465
1
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.

I'm an idiot. I've been using Mac OS since OS 9 and I made that error. Many thanks for the sanity check!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.