Process finished with exit code -1073741819 (0xC0000005) - C, Clion

0

I am running my InitializeMsgQs() function:

struct MsgQs_t *pst;

struct MsgQs_t queue[10];

void initializeMsgQs() {
    int qNumber = 0;
    printf("Enter queue number:\n");
    scanf("%d", &qNumber);
    *pst = queue[qNumber];
    printf("Enter identifier: \n");
    // assigning the identifier as an element in the queue array
    scanf("%d", &queue[qNumber].id);

}

Once i enter the queue number,i am prompted with: Process finished with exit code -1073741819 (0xC0000005), when i should be asked to enter queue identifier.

queue is a struct array of size 10, and id is of type int, inside the main struct.

c
struct
clion
asked on Stack Overflow Jan 7, 2020 by Nicole • edited Jan 7, 2020 by Nicole

1 Answer

0

*pst = queue[qNumber]; should be pst = &queue[qNumber];. queue is an array of structures and pst is a pointer to such a structure. So you must place the address of the queueu structure in pst.

Writing *pst = queue[qNumber]; is correct and would mean to assign the data of the queue element to what pst is pointing to. However, pst is not pointing anywhere (it is still 0).

See also the comment of Ctx about checking that a valid number was read.

answered on Stack Overflow Jan 7, 2020 by Paul Ogilvie

User contributions licensed under CC BY-SA 3.0