Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve exit code 139 error when reading from file on unix

Tags:

c

unix

So I believe this is just a problem on unix and that it occurs at the first fscanf if the Clion debugger was right, but I don't know why I get the error- Process finished with exit code 139 (interrupted by signal 11: SIGSEGV) - why?

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
like image 912
michael lee Avatar asked Mar 19 '17 02:03

michael lee


2 Answers

It means the program crashed before it exited. You need to debug the program. For example, you need to check whether the file is successfully opened after fopen.

like image 131
xuhdev Avatar answered Sep 22 '22 09:09

xuhdev


SIGSEGV are not always thrown due to a root cause of memory access problems...

Perl throws a 139 on Unix usually because of file I/O. You might have accidentally deleted your input files.

like image 23
BAMF4bacon Avatar answered Sep 21 '22 09:09

BAMF4bacon