Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- //Se non erro bisognava creare una lista di nodi, salvarla su file, e poi creare una funzione che preleva la lista dal file, con i dovuti controlli sul campo nodo.next xche essendo un indirizzo alla riapertura del programma il nodo non sta più in quel vecchio indirizzo e quindi bisognava riassegnargli un nuovo indirizzo
- struct lista
- {
- char numero;
- struct lista *prossimo;
- };
- struct lista *creanodo(struct lista *testa,char x);
- int main (void)
- {
- char x=0;
- struct lista *testa;
- testa=NULL;
- printf("Inserisci elemento (a capo per terminare)\n");
- for(;;)
- {
- scanf("%c",&x);
- if(x=='\n')
- break;
- testa=creanodo(testa,x);
- }
- FILE *input, *output;
- input=fopen("lista1.txt","w");
- if(input==NULL)
- {
- printf("Errore\n");
- return 0 ;
- }
- for(testa;testa!=NULL;testa=(*testa).prossimo)
- {
- putc((*testa).numero,input);
- }
- fclose(input);
- input=fopen("lista1.txt","r");
- output=fopen("lista2.txt","w");
- if(input==NULL||output==NULL)
- {
- printf("Errore\n");
- return 0 ;
- }
- while((x=getc(input))!=EOF)
- {
- putc(x,output);
- }
- fclose(input);
- fclose(output);
- }
- struct lista *creanodo(struct lista *testa,char x)
- {
- struct lista *nuovo;
- nuovo=malloc(sizeof(struct lista));
- (*nuovo).numero=x;
- (*nuovo).prossimo=testa;
- return nuovo;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement