Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <malloc.h>
- typedef struct nodo *lista;
- typedef struct nodo{
- char nome[25];
- lista next;
- } nodo;
- lista insCoda(lista L,char c[])
- {
- nodo *n,*tmp=L;
- n=malloc(sizeof(nodo));
- if(!n)
- {
- printf("MEMORIA ESAURITA!");
- return L;
- }
- strcpy(n->nome,c);
- n->next=NULL;
- while(tmp->next!=NULL) tmp=tmp->next;
- tmp->next=n;
- return L;
- }
- lista leggiLista(lista L)
- {
- int n;
- char c[25];
- printf("\nQuanti valori vuoi inserire?");
- scanf("%d",&n);
- while(n--)
- {
- printf("\nInserisci il nome: ");
- scanf("%s",c);
- if(!L)
- { L=malloc(sizeof(nodo));
- if(!L) return NULL;
- strcpy(L->nome,c);
- L->next=NULL;
- }
- else L=insCoda(L,c);
- }
- return L;
- }
- void stampaLista(lista L)
- {
- while(L)
- {
- printf("\n%s",L->nome);
- L=L->next;
- }
- }
- int main(void)
- {
- lista L=NULL;
- L=leggiLista(L);
- stampaLista(L);
- return 0;
- }
Add Comment
Please, Sign In to add comment