Why can not I print content in Linked List

0

Good evening, I have a problem with a college job. I need to create a linked list that receives student records. I created a function to register, however, I can not externally print the contents of it using the first one's pointer. I would like to know why this is happening.

For example, within the scope of the function it can print with (*((*a).alunoPosterior)).nome) , but when I go outside I can not do it using (*(a.alunoPosterior)).nome .

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <locale.h>

#define length 100

typedef struct aluno {
    int matricula;
    int telefone;

    double n1;
    double n2;
    double n3;
    double media;

    char nome[length];
    char email[length];

    struct aluno *alunoAnterior;
    struct aluno *alunoPosterior;
} Aluno;

void criarAluno(Aluno *a);

int main() {
    setlocale(LC_ALL, "Portuguese");

    Aluno a;

    gets(a.nome);
    criarAluno(&a);

    printf("NOME A = %s\nNOME B = %s", a.nome,  (*(a.alunoPosterior)).nome);

    return 0;
}

/**
    A função cria um struct de Aluno. Em seguida, vincula o struct recém-criado ao ponteiro (*a)
    do mesmo tipo que veio através do parâmetro.
*/
void criarAluno(Aluno *a) {
    Aluno b;

    fflush(stdin);

    printf("Insira o nome do aluno: ");
    gets(b.nome);

  /*  printf("\nInsira o número de matrícula do aluno: ");
    scanf("%d", &b.matricula);

    printf("\nInsira o número de telefone do aluno: ");
    scanf("%d", &b.telefone);

    printf("\nInsira a Nota 1: ");
    scanf("%d", &b.n1);

    printf("\nInsira a Nota 2: ");
    scanf("%d", &b.n2);

    printf("\nInsira a Nota 3: ");
    scanf("%d", &b.n3);

    b.media = (b.n1 + b.n2 + b.n3)/3;*/

    (*a).alunoPosterior = &b;

    printf("%s\n\n", (*((*a).alunoPosterior)).nome);
    b.alunoAnterior = a;
}

Anyone know what I can do?

    
asked by anonymous 24.10.2015 / 02:28

1 answer

0

I was able to respond when I replaced the Aluno b statement with:

Aluno *b = (Aluno*) malloc(sizeof(Aluno));
    
24.10.2015 / 05:08