Program C stops when pointer receives value of variable

0

My function is returning the following error when executing the program: Process returned -1073741819 (0xC0000005).

Until the moment I assign the inputs to the variables, it works. However, when the program is going to assign the values of the variables to the pointers, the program stops.

void Cadastrar(pessoas *p){
    char nome[50];
    int idade;
    char sexo;
    char endereco [200];

    printf("Digite o nome: ");
    fflush(stdin);
    scanf("%s",nome);
    fflush(stdin);

    printf("Digite a idade: ");
    scanf("%d",&idade);

    printf("Escolha o sexo: ");
    fflush(stdin);
    sexo = getchar();
    fflush(stdin);

    printf("Digite o endereco: ");
    fflush(stdin);
    scanf("%s",endereco);
    fflush(stdin);

    strncpy(p->nome,nome, sizeof(nome));
    p->idade = idade;
    p->sexo = sexo;
    strncpy(p->endereco,endereco, sizeof(nome));

}
c
pointers
variables
struct
asked on Stack Overflow May 18, 2021 by Junior Kubiak • edited May 18, 2021 by Jonathan Leffler

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0