mittimus

Implementazione LIST con puntatori

Jul 17th, 2012
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.27 KB | None | 0 0
  1. #define FLUSH while(getchar()!='\n')
  2. #define S 15
  3. typedef struct {
  4. char cognome[S], nome[S];
  5. unsigned short eta;
  6. }tipobaseList;
  7. void LeggiStringa(char s[],unsigned long dim){
  8. unsigned long i=0;
  9. for (i=0; (s[i]=getchar())!='\n' && i<dim-1;i++);
  10. s[i]='\0';
  11. if (i==dim-1) while (getchar()!='\n');
  12. }
  13. void LeggiElementoList(tipobaseList * x){
  14. printf("\nInserisci l'Elemento ");
  15. printf("\nInserisci il Cognome ");
  16. LeggiStringa(x->cognome, S);
  17. printf("\nInserisci il Nome ");
  18. LeggiStringa(x->nome, S);
  19. printf("\nInserisci l'eta' ");
  20. scanf("%d",&x->eta);
  21. FLUSH;
  22. }
  23. void CercaElementoList(tipobaseList * x){
  24. printf("\nRicerca per Cognome e Nome ");
  25. printf("\nInserisci il Cognome ");
  26. LeggiStringa(x->cognome, S);
  27. printf("\nInserisci il Nome ");
  28. LeggiStringa(x->nome, S);
  29. }
  30. void VisualizzaElementoList(tipobaseList x){
  31. printf("\n\nElemento ");
  32. printf("\nCognome = %s ", x.cognome);
  33. printf("\nNome = %s ", x.nome);
  34. printf("\nEta' = %d \n\n",x.eta);
  35. }
  36.  
  37.  
  38. void ModificaElementoList(tipobaseList * x){
  39. printf("\nModifica l'Eta' = % d ",x->eta);
  40. printf("\nInserisci la nuova Eta' ");
  41. scanf("%d",&x->eta);
  42. FLUSH;
  43. }
  44. int Confronta(tipobaseList a, tipobaseList b){
  45. if (!strcmp(a.cognome,b.cognome))
  46. return strcmp(a.nome,b.nome);
  47. else return strcmp(a.cognome,b.cognome);
  48. }
Advertisement
Add Comment
Please, Sign In to add comment