Max Sher
Max Sher

Reputation: 13

Xcode Seemingly Unable to Use Arrays in C

It's very likely that this is user error as I'm somewhat new to Xcode, but I can't figure this out. Hopefully one of you can.

I'm trying to add an array using the following code:

int ArraySum (int MyArray [], int size) {
    int sum = 0;
    for (int i = 0; i< size; i++) {
        sum = sum + MyArray [i];
    }
    return sum;
}

int main (){
    int mynumberarray [6] = {1,2,3,4,5,6};
    int the_sum = ArraySum (mynumberarray, 6);
    printf ("The Sum is = %d \n", the_sum);
    return 0;
}

When I click the build & run button in Xcode, the only output I get is (lldb).

This would typically lead me to believe that I made a mistake somewhere, but when I run the code through Terminal it runs perfectly and gives me the correct sum.

Can anyone help me here? This isn't an isolated incident, I've had several issues working with arrays in Xcode that are working perfectly when executed in Terminal.

Screenshot:

enter image description here

Upvotes: 1

Views: 45

Answers (1)

Paul R
Paul R

Reputation: 212969

You have breakpoints set in your Xcode project, so the program is pausing at the first breakpoint and giving you the (lldb) debugger prompt. Disable the breakpoints and run and everything should behave as expected. You can either manually disable each breakpoint (by clicking on it - it should then become dimmed), or go to Debug => Disable Breakpoints in the menu bar.

Upvotes: 2

Related Questions