Chained list - [Error] Storage size of 'mylist' isn’t known

Asked

Viewed 518 times

0

I’m having trouble developing a chain list, so please help me. Every time I try to compile error appears on line 7 [Error] Storage size of 'mylist' isn’t known

inserir a descrição da imagem aqui

I’ve already changed the place structure, I’ve fucked everything but still having trouble

Main file. c

#include <stdio.h>
#include <stdlib.h>
#include "lista.h"

void main () {

    struct ListaSimplesEnc minhaLista;

    criarLista(&minhaLista);

    int valor, op;

    while( 1 ){

        printf( "1 - Inserir elemento no inicio\n" );
        printf( "2 - Inserir elemento em ordem (so se a lista estiver ordenada)\n" );
        printf( "3 - Remover elemento no inicio\n" );
        printf( "4 - Remover elemento\n" );
        printf( "5 - Mostrar lista\n" );
        printf( "6 - Sair\n" );
        printf( "Opcao? " );
        scanf( "%d", &op );

        switch( op ){

            case 1: // inserir elemento no inicio

                printf( "Valor? " );
                scanf( "%d", &valor );
                inserirIni(&minhaLista, valor);
                break;
            case 2: // inserir elemento ordenado
                printf( "Valor? " );
                scanf( "%d", &valor );
                inserirOrd(&minhaLista, valor);
                break;
            case 3: // remover o primeiro
                break;
            case 4: // remover determinado elemento
                break;
            case 5: //  mostrar lista
                if (estaVazia(&minhaLista)) {
                    printf("Lista vazia");
                }
                else {
                    mostrarLista(&minhaLista);
                }
                break;
            case 6: // abandonar o programa
                exit(0);
        }

    }
}

List file. c

#include <stdio.h>
#include <stdlib.h>
#include "lista.h"

struct Nodo {

    int info;
    struct Nodo *prox;

};

struct ListaSimplesEnc {

    struct Nodo *prim;

};

void criarLista (struct ListaSimplesEnc *pList) {

    pList -> prim = NULL;

}

void mostrarLista (struct ListaSimplesEnc *pList){

    struct Nodo *p;

    for (p = pList -> prim; p != NULL; p = p->prox) {

        printf("%d\t", p->info);

    }

    printf("\n");

}

void inserirIni (struct ListaSimplesEnc *pList, int v){
    struct Nodo *novo;
    novo = (struct Nodo*) malloc (sizeof (struct Nodo));
    novo -> info = v;
    novo -> prox = pList -> prim;
    pList -> prim = novo;
}

void removerIni (struct ListaSimplesEnc *pList){

    struct Nodo *pAux = pList -> prim;
    pList -> prim = pList -> prim -> prox;
    free(pAux);

}

void inserirOrd (struct ListaSimplesEnc *pList, int v){
    struct Nodo *novo;
    novo = (struct Nodo*) malloc (sizeof (struct Nodo));
    novo -> info = v;

    struct Nodo *pAtu, *pAnt;

    pAnt = NULL;
    pAtu = pList -> prim;

    while ( pAtu != NULL && pAtu->info < v){

        pAnt = pAtu;
        pAtu = pAtu -> prox;

    }

    novo -> prox = pAtu -> prox;
    pAnt -> prox = novo;
}

int estaVazia(struct ListaSimplesEnc *pList) {

    return (pList->prim == NULL);

}

list. h

struct ListaSimplesEnc minhaLista;

void criarLista (struct ListaSimplesEnc *pList);

void mostrarLista (struct ListaSimplesEnc *pList);

void inserirIni (struct ListaSimplesEnc *pList, int v);

void removerIni (struct ListaSimplesEnc *pList);

void inserirOrd (struct ListaSimplesEnc *pList, int v);

int estaVazia(struct ListaSimplesEnc *pList);
  • you need to give details, no one will be able to guess the problems...

  • @zentrunix Every time I try to compile the error "Error [Warming] 'struct Listasimlesenc' declared Inside Parameter list" appears. , I’ve changed the place structure, I’ve noticed everything but still having trouble

  • you have to put the explanations and details (e.g. which line is giving error ? which font is giving error ?) in the question, and not in the comments

  • 1

    Declare your structs in the file . h

  • that’s not how this site works...you do the program, and when you have a specific difficulty you ask here about that specific difficulty...then usually someone will appear to help...but it has to be a specific problem because this is not a mentoring site

2 answers

1


You need to declare the structures in . h and not us . c.

Example:

List file. c

#include <stdio.h>
#include <stdlib.h>
#include "lista.h"

// struct Nodo
// {
//   int info;
//   struct Nodo *prox;
// };

// struct ListaSimplesEnc
// {
//   struct Nodo *prim;
// };

struct ListaSimplesEnc minhaLista;

// ...
// ...

List file. h

struct Nodo
{
  int info;
  struct Nodo *prox;
};

struct ListaSimplesEnc
{
  struct Nodo *prim;
};

extern struct ListaSimplesEnc minhaLista;

// ...
  • thank you very much, I made the change and it worked!

  • then please mark my answer as accepted

0

Declare your structs in the file . h

Browser other questions tagged

You are not signed in. Login or sign up in order to post.