线程 1:EXC_BAD_ACCESS (code=EXC_I386_GPFLT) 导致我的 scanf 失败

Thread 1: EXC_BAD_ACCESS (code=EXC_I386_GPFLT) is causing my scanf to fail

#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)
}

我有更多代码,但与问题无关。感谢您的帮助,只是询问是否需要更多信息(我正在制作一个计算器来排列输入并计算它们 例如。 3 + 5 * 9 / 2 = 36。等式最多可以有50个整数和49个运算。)

您以字节为单位计算数组的大小,而不是元素的数量。改为这样做:

for( int i = 0; i < sizeof(nums) / sizeof(nums[0]); i++ )
{