Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- typedef struct nodo *Lista;
- typedef struct nodo{
- char nome[20];
- char cognome [20];
- Lista next;
- }nodo;
- //prototipi funzione
- Lista crealista();
- void stampalista(Lista L);
- void stampaPrimo(Lista L, char lettera);
- int main ()
- {
- Lista list=NULL;
- char lettera;
- list=crealista();
- //stampalista(list);
- printf("inserisci la lettera del nome\n");
- scanf("%c", &lettera);
- stampaPrimo(list, lettera);
- return 0;
- }
- Lista crealista()
- {
- nodo *N;
- Lista list=NULL;
- char buf[20];
- while(1)
- {
- printf("\ninserisci nome ($ per terminare)\n");
- gets(buf);
- if(strcmp(buf,"$")==0) break;
- N=malloc(sizeof(nodo));
- strcpy(N->nome,buf);
- printf("\ninserisci cognome\n");
- gets(N->cognome);
- N->next=list;
- list=N;
- }
- return list;
- }
- void stampaPrimo(Lista L, char lettera)
- {
- while(L)
- {
- if(L->nome[0]==lettera)
- {
- printf("%s", L->cognome);
- break;
- }
- L=L->next;
- }
- if(!L) printf("nessun nome corrispondente");
- }
- void stampalista(Lista L)
- {
- while(L)
- {
- printf("\n%s\n", L->nome);
- printf("\n%s\n",L->cognome);
- L=L->next;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement