request for member 'attributeDisplay' in something not a structure or union

0

Tree initialization error, the problem with category variables and atributoOuDecisao .

typedef struct node {
    int categoria;
    int atributoOuDecisao;
    struct node *prox;
    struct node *lista;
} No;

No *criaArvore(void){
    No *inicio = (No*)malloc(sizeof(No));
    inicio.atributoOuDecisao = NULL;
    inicio.categoria = NULL;
    inicio->lista = NULL;
    inicio->prox = NULL;
    printf ("inicio criado");
    return inicio;
}
    
asked by anonymous 16.10.2016 / 20:12

1 answer

2

When you use a pointer to a structure the correct operator to access the members is always -> . In addition, integer types must be initialized with 0 and not with NULL .

#include <stdio.h>
#include <stdlib.h>
typedef struct node {
    int categoria;
    int atributoOuDecisao;
    struct node *prox;
    struct node *lista;
} No;

No *criaArvore(void){
    No *inicio = malloc(sizeof(No));
    inicio->atributoOuDecisao = 0;
    inicio->categoria = 0;
    inicio->lista = NULL;
    inicio->prox = NULL;
    printf ("inicio criado");
    return inicio;
}

int main() {
    criaArvore();
}

See running on ideone and on CodingGround .

    
16.10.2016 / 20:24