Precedente :: Successivo |
Autore |
Messaggio |
Luca Rizzo Mortale devoto
Registrato: 13/10/15 20:51 Messaggi: 13
|
Inviato: 06 Mar 2017 22:19 Oggetto: programmazione in C |
|
|
Salve a tutti.
C'è un modo alternativo e più corto per creare questa lista ?
Grazie in anticipo
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct SOFTWARE {
char nome_programmatore[20];
char nome_programma[20];
int righe_aggiunte;
int righe_tolte;
}software;
typedef struct LISTA_SOFTWARE {
software dati;
struct LISTA_SOFTWARE *next;
}lista_software;
lista_software *add_element(software t, lista_software *root);
lista_software *riempi_da_file(lista_software *root);
int main () {
lista_software *root = NULL;
root = riempi_da_file(root);
return 0;
}
lista_software *add_element(software t, lista_software *root) {
lista_software *nuovo;
nuovo = (lista_software *)malloc(sizeof(lista_software));
nuovo->dati = t;
nuovo->next = root;
return nuovo;
}
lista_software *riempi_da_file(lista_software *root){
FILE *fp = fopen("progetto.txt", "r");
software t;
while( fscanf(fp, "%s%s%d%d", &t.nome_programmatore,&t.nome_programma,&t.righe_aggiunte, &t.righe_tolte
)==4){
root = add_element(t, root);
}
fclose(fp);
return root;
} |
|
Top |
|
|
SverX Supervisor Macchinisti
Registrato: 25/03/02 11:16 Messaggi: 11566 Residenza: Tokelau
|
Inviato: 07 Mar 2017 10:26 Oggetto: |
|
|
più corto? |
|
Top |
|
|
Luca Rizzo Mortale devoto
Registrato: 13/10/15 20:51 Messaggi: 13
|
Inviato: 07 Mar 2017 11:25 Oggetto: |
|
|
Tu che metodo usi per esempio ? |
|
Top |
|
|
SverX Supervisor Macchinisti
Registrato: 25/03/02 11:16 Messaggi: 11566 Residenza: Tokelau
|
Inviato: 08 Mar 2017 16:28 Oggetto: |
|
|
per caricare una lista di quel tipo? io farei un inserimento in testa, esattamente quello che fai tu
se trovi che questo codice sia troppo lungo per caricare una lista (!!!) passa a Python... |
|
Top |
|
|
|