在 unix 上读取文件时如何解决退出代码 139 错误

mic*_*lee 8 c unix

所以我相信这只是 unix 上的一个问题,如果 Clion 调试器是正确的,它会发生在第一个 fscanf 上,但我不知道为什么我会收到错误 - 进程已完成,退出代码为 139(被信号 11 中断:SIGSEGV ) - 为什么?

struct loginInformation
{
    char username[USERNAME_LENGTH];
    char password[PASSWORD_LENGTH];
    int type;
}accounts[NUM_OF_ACCOUNTS];

void createAccountsFromFile()
{
    FILE *input = fopen("accounts.txt", "r");
    int counter;
    for(counter = 0; counter < NUM_OF_ACCOUNTS; counter++)
    {
        fscanf(input, "%s", accounts[counter].username);
        fscanf(input, "%s", accounts[counter].password);
        fscanf(input, "%d", &accounts[counter].type);
    }
}

int main()
{
    createAccountsFromFile();
}

accounts.txt

user1
pass1
0
user2
pass2
1
user3
pass3
2
user4
pass4
3
Run Code Online (Sandbox Code Playgroud)

xuh*_*dev 7

这意味着程序在退出之前崩溃了。您需要调试程序。例如,您需要检查文件是否在fopen.