Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it
    Registrato dal
    Mar 2014
    Messaggi
    78

    expected primary expression before token [c++]

    Salve sono alle prese con un programma per la gestione dei laboratori di ricerca italiani.
    A cosa è dovuto il seguente errore :expected primary expressione before token *
    nella riga :
    codice:
    TNode_list *new;
    contenuta nella funzione:
    codice:
    TNode_list *node_create_list(TInfo_list info)
    ecco il codice completo:

    codice:
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    #include <stdbool.h>
    #define MAXLEN 16
    /****************************************************************************
     STRUTTURE DATI
     NOTA: sulla base delle particolari esigenze, potrebbe essere possibile 
     dover invertire l'ordine! Pertanto il seguente listato di codice può 
     essere modificato
     ****************************************************************************/
    typedef struct SKey{
     int codice;        
    }TKey;
    typedef struct SSat_list{ 
     /*
      COMPLETARE IL CAMPO SATELLITE RELATIVO ALLA STRUTTURA LISTA
      */
     
     char cognom[MAXLEN];
     char ruolo;
     int num_cit;
     
    } TSat_list;
    typedef struct SInfo_list{
     TKey key;
     TSat_list satellite;        
    } TInfo_list;
    typedef struct SNode_list{
     TInfo_list info;
     struct SNode_list *link;
    } TNode_list;
    typedef TNode_list *TList;
    typedef struct SSat_tree{
     /*
      COMPLETARE IL CAMPO SATELLITE RELATIVO ALLA STRUTTURA ALBERO
      */
      char nome_lab[MAXLEN];
      char citta[MAXLEN];
      TList punt;                           /*ho ancora qualche dubbio*/
    } TSat_tree;
    typedef struct SInfo_tree{
     TKey key;
     TSat_tree sat;        
    } TInfo_tree;
    typedef struct SNode_tree{
     TInfo_tree info;
     struct SNode_tree *right;
     struct SNode_tree *left;
    } TNode_tree;
    typedef TNode_tree *TTree;
    /****************************************************************************
     FINE DICHIARAZIONI STRUTTURE DATI
     ****************************************************************************/       
     
     
    /****************************************************************************
     FUNZIONI DI GESTIONE DELLA CHIAVE TKey, PER LISTE E ALBERI
     ****************************************************************************/
    bool greater (TKey key1, TKey key2);
    bool lower (TKey key1, TKey key2);
    bool equal (TKey key1, TKey key2);
    void print_key (TKey key);
    TKey read_key();
    /* CLEARS STDIN OF ANY WAITING CHARACTERS */
    void clear_stdin(void) {
     char junk[80];
     fgets(junk,80,stdin);
    }
    bool greater (TKey key1, TKey key2)
    {
        if (key1.codice > key2.codice)
            return true;
        else
            return false;
    }
    bool lower (TKey key1, TKey key2)
    {
        if (key1.codice < key2.codice)
            return true;
        else
            return false;
    }
    bool equal(TKey key1, TKey key2)
    {
        if (key1.codice == key2.codice)
            return true;
        else
            return false;
    }
    void print_key (TKey key)
    {
        printf ("\n%d\t", key.codice);
    }
    TKey read_key(){
        TKey key;
        printf("\nInserire chiave: ");
        scanf("%d",&key.codice);
        return key;
    }
     
    /****************************************************************************
     FUNZIONI DI GESTIONE DELLE LISTE
     ****************************************************************************/
    TList list_create();
    TList list_destroy(TList list);
    TNode_list *node_create_list(TInfo_list info);
    void node_destroy_list(TNode_list *node);
    TNode_list *list_search(TList list, TKey key);
    TList list_insert(TList list, TInfo_list info);
    TList list_delete(TList list, TKey key);
    /* Crea e restituisce una lista vuota */
    TList list_create() {
        return NULL;
    }
    /* Distrugge la lista list, deallocandone tutti gli elementi
     * NOTA: consuma il parametro list
     */
    TList list_destroy(TList list) {
        TNode_list *curr, *succ;
        curr = list;
        while (curr != NULL) {
            succ = curr->link;
            node_destroy_list(curr);
            curr = succ;
        }
        return NULL;
    }
    /* Crea ed alloca un nodo della struttura lista*/
    TNode_list *node_create_list(TInfo_list info) {
     TNode_list *new;
        
     new=(TNode_list *) malloc(sizeof(TNode_list));
     if (new==NULL) {
      printf("errore allocazione memoria.\n");
      return NULL;
     }
     new->info = info;
     new->link = NULL;
     return new;
    }
    /* Distrugge e dealloca un nodo */
    void node_destroy_list(TNode_list *node) {
        free(node);
    }
    
    /* Cerca l'elemento di valore info nella Lista list. Ritorna il
     * riferimento all'elemento se e' presente, altrimenti ritorna NULL.
     * PRE: list e' ordinata
     */
    TNode_list *list_search(TList list, TKey key) {
        
     if (list == NULL || greater(list->info.key, key))
            return NULL;
        
        else {
            if (equal(list->info.key, key))
                return list;
            
            else
                return list_search(list->link, key);
        }
    }
    /* Inserisce l'elemento di valore info nella Lista ordinata list. */
    TList list_insert(TList list, TInfo_list info) {
     if (list==NULL || greater(list->info.key, info.key) ) {
      TNode_list* newnode;
      newnode = node_create_list(info);
      if (newnode==NULL) {
       printf ("Errore di allocazione della memoria\n");
       exit(1);
      }
      newnode->link = list;
      return newnode;
     }
        else {
            TList l2;
            l2 = list_insert(list->link,info);
            list->link = l2;
            return list;
        }
    }
    /* Cancella l'elemento di valore info nella lista list, preservando
     * l'ordinamento; restituisce la lista risultante.
     * PRE: list e' ordinata
     * NOTA: consuma il parametro list; se l'elemento da cancellare non
     e' presente,   la lista resta inalterata.
     */
    TList list_delete(TList list, TKey key) {
        if (list == NULL || greater(list->info.key, key))
            return NULL;
        
        else
     {
            if (equal(list->info.key, key)) { /* cancellazione in testa */
                TNode_list *alias = list->link;
                node_destroy_list(list);
                return alias;
            }
            
            else {
                TList l2;
                l2 = list_delete(list->link, key);
                list->link = l2;
                return list;
            }
        }
    }
     
    
    /****************************************************************************
     FUNZIONI ALBERI
     ****************************************************************************/
    TTree tree_create();
    TTree tree_destroy(TTree tree);
    TNode_tree *node_create_tree(TInfo_tree info);
    void node_destroy_tree(TNode_tree *node);
     
    TNode_tree* tree_search(TTree tree, TKey Key);
    TTree tree_insert(TTree tree, TInfo_tree info);
    TTree tree_delete(TTree tree, TKey key);
    bool tree_empty(TTree tree);
    TNode_tree* tree_min(TTree tree);
    
    /* Crea e restituisce un albero vuoto */
    TTree tree_create()
    {
        return NULL;
    }
    /* Distrugge l'albero tree, deallocandone tutti gli elementi
     * NOTA: consuma il parametro tree
     */
    TTree tree_destroy(TTree tree) {
        if(tree==NULL)
            return NULL;
        else if((tree->left==NULL) && (tree->right==NULL)) {
            free(tree);
            return NULL;
        }
        else {
            tree->left = tree_destroy(tree->left);
            tree->right = tree_destroy(tree->right);
            free(tree);
            return NULL;
        }
    }
    /* Crea ed alloca un nodo della struttura albero*/
    TNode_tree *node_create_tree(TInfo_tree info)
    {
        TNode_tree* node;
     
        node=(TNode_tree*)malloc(sizeof(TNode_tree));
        if(node==NULL){
            printf("\nErrore allocazione memoria.\n");
            return NULL;
        }
        node->info=info;
        node->left=NULL;
        node->right=NULL;
        return node;
    }
    /* Distrugge e dealloca un nodo della struttura alberp */
    void node_destroy_tree(TNode_tree *node) {
        free(node);
    }
    
    /* Cerca l'elemento di valore info nell'albero tree. Ritorna il
     * riferimento all'elemento se e' presente, altrimenti ritorna NULL.
     * PRE: tree e' ordinato
     */
    TNode_tree* tree_search(TTree tree, TKey key){
        if((tree==NULL) || equal(tree->info.key, key))
            return tree;
        else
        {
            if(greater(key, tree->info.key))
                return tree_search(tree->right, key);
            else
                return tree_search(tree->left, key);
        }
    }
    /* Inserisce l'elemento di valore info nell'albero ordinato tree. */
    TTree tree_insert(TTree tree, TInfo_tree info)
    {
        if(tree==NULL){
            TNode_tree* newnode;
            newnode=(TNode_tree*) malloc(sizeof(TNode_tree));
            if(newnode==NULL){
                printf("Errore di allocazione");
                exit(1);
            }
            newnode->right=newnode->left=NULL;
            newnode->info=info;
            return newnode;
        }
        else if(!greater(info.key,tree->info.key)){
            tree->left=tree_insert(tree->left,info);
            return tree;
        }
        else{
            tree->right=tree_insert(tree->right,info);
            return tree;
        }
    }
    /* Cancella l'elemento di valore info nell'albero tree, preservando
     * l'ordinamento; restituisce l'albero risultante.
     * PRE: tree e' ordinato
     * NOTA: consuma il parametro tree; se l'elemento da cancellare non
     e' presente, l'albero resta inalterato.
     */
    TTree tree_delete(TTree tree, TKey key) {
        if(tree==NULL)
            return NULL;
        else if(greater(tree->info.key, key)) {
            tree->left=tree_delete(tree->left, key);
            return tree;
        }
        else if(greater(key, tree->info.key)) {
            tree->right=tree_delete(tree->right, key);
            return tree;
        }
        else{ /* tree->info.key==key */
            TTree min_right;
            if((tree->right==NULL) && (tree->left==NULL)) {
                free(tree); /* Cancellazione di una foglia */
                return NULL;
            }
            if(tree->right==NULL) { /* Cancellazione di un nodo con
                                     il solo figlio sinistro */
                TTree alias;
                alias = tree->left;
                free(tree);
                return alias;
            }
            if(tree->left==NULL) { /* Cancellazione di un nodo con
                                    il solo figlio destro */
                TTree alias;
                alias=tree->right;
                free(tree);
                return alias;
            }
            /* Cancellazione di un nodo con entrambi i figli */
            min_right=tree_min(tree->right); /* Ricerca del minimo del
                                              sottoalbero destro */
            tree->info=min_right->info; /* Copia del minimo nel campo info
                                         del nodo da eliminare */
            /* Eliminazione del nodo da cui Ë stato copiato il minimo */
            tree->right=tree_delete(tree->right,min_right->info.key);
            return tree;
        }
    }
    /*La funzione restituisce true se l'albero e' vuoto, false altrimenti. */
    bool tree_empty(TTree tree)
    {
        if(tree==NULL)
            return true;
        else
            return false;
    }
    /*La funzione restituisce il nodo associato alla chiave minima. */
    TNode_tree* tree_min(TTree tree)
    {
        if(tree==NULL)
            return NULL;
        else
        {
            if(tree->left!=NULL)
                return tree_min(tree->left);
            else
                return tree;
        }
    }
     
    /****************************************************************************
     INSERIRE QUI LE FUNZIONI DA SCRIVERE
     ****************************************************************************/
     
    
    /****************************************************************************
     FINE FUNZIONI
     ****************************************************************************/     
     
    
    /****************************************************************************
     SCRIVERE IL MAIN
     ****************************************************************************/
    int main()
    {  
        int scelta; 
        
        
        printf("Programma gestione laboratorio!\n\n");
        printf("1 Inserimento nuovo laboratorio\n");
        printf("2 Inserimento nuovo docente\n");
        printf("3 Aggiunta di una nuova citazione\n");
        printf("4 Ricerca docente con il maggior numero di citazioni\n");
        printf("5 Docenti con citazioni superiori ad una soglia\n");
        printf("6 Stampa docenti con una particolare tipologia\n");
        
        printf("Quale operazione vuoi compiere\n");
        scanf("%d",&scelta);
        while(scelta<1 ||scelta >6)
        {
             printf("Digita l'operazione da compiere");
             scanf("%d",&scelta);
       }
        
     
    }

  2. #2
    Utente di HTML.it L'avatar di Alex'87
    Registrato dal
    Aug 2001
    residenza
    Verona
    Messaggi
    5,802
    new è una parola riservata in C++ (serve per creare un nuovo oggetto).

    Non puoi usarla come nome di una variabile.




    Parentesi: dici di usare C++ ma in quel codice non vedo nulla di C++ (a parte bool ), è C.
    Se vuoi usare C++ usa le classi al posto delle struct e string al posto degli array di char terminati da \0 ecc ecc...
    Ultima modifica di Alex'87; 25-06-2014 a 13:00
    SpringSource Certified Spring Professional | Pivotal Certified Enterprise Integration Specialist
    Di questo libro e degli altri (blog personale di recensioni libri) | ​NO M.P. TECNICI

  3. #3
    Utente di HTML.it
    Registrato dal
    Mar 2014
    Messaggi
    78
    grz mille lo stesso ho salvato il file come .c invece che .c++ e va tutto ok..grazie..per l'illuminazione

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.