0
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
int main(int argc, const char * argv[]) {
    bool isTrue=true;
    int nums[50];
    for (int i = 0; i<sizeof(nums); i++) {
        nums[i]=2147483647;
    }
    char operations[49];
    int counter = 0;
    printf("What is your first number? (THERE IS NO PEMDAS, THE NUMBER 2147483647 is not allowed)\n");
    scanf("%d", &nums[counter]); // Thread 1: EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
}

I have more code, but it is unrelated to the problem. Thank you for helping and just ask if more info is needed (I am making a calculator that lines up inputs and calcultes them eg. 3 + 5 * 9 / 2 = 36. The equation can have at most 50 integers and 49 operations.)

S.S. Anne
  • 15,171
  • 8
  • 38
  • 76
  • 3
  • 2
    Don't give us half of your function. Give us all of it. Or at least make it compile with only half. – S.S. Anne Jan 02 '20 at 21:51
  • 1
    the posted code contains some 'magic' numbers. 'magic' numbers are numbers with no basis. 'magic' numbers make the code much more difficult to understand, debug, etc. Suggest using `#define` statements or a `enum` statement to give those 'magic' numbers meaningful names, then use those meaningful names throughout the code. – user3629249 Jan 03 '20 at 16:06

1 Answers1

2

You're taking the size of your array in bytes, not in the number of elements. Do this instead:

for( int i = 0; i < sizeof(nums) / sizeof(nums[0]); i++ )
{
S.S. Anne
  • 15,171
  • 8
  • 38
  • 76