Guest User

Untitled

a guest
Jun 24th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.71 KB | None | 0 0
  1. #include "header.h"
  2.  
  3. void LeggiVettore(studente st[],int*n){
  4.      int i;
  5.      int m=0;
  6.      puts("\nInserire quanti elementi si vogliono inserire: ");
  7.      scanf("%d" ,&m);
  8.      getchar();
  9.      printf("\nInserire %d studenti: \n",m);
  10.      for(i=0;i<m;i++){
  11.                       printf("\nInserire studente %d" ,i+1);
  12.                       puts("\nInserire cognome e nome: ");
  13.                       gets(st[i].Nominativo);
  14.                       puts("\nInserire Data di nascita: ");
  15.                       scanf("%d" ,&st[i].dataN.anno);
  16.                       puts("\nInserire Mese: ");
  17.                       scanf("%d" ,&st[i].dataN.mese);
  18.                       puts("\nInserire Anno: ");
  19.                       scanf("%d" ,&st[i].dataN.anno);
  20.                       puts("\nInserire sesso: ");
  21.                       scanf("%s" ,&st[i].sesso);
  22.                       puts("\n");
  23.                       getchar();
  24.                       }
  25.      *n=m;
  26.      }
  27.      
  28. void SalvaSuFile(FILE*out,studente st[],int n){
  29.      int i;
  30.      if(out==NULL) printf("\nIl file non può essere aperto!");
  31.      else{
  32.      for(i=0;i<n;i++){
  33.                       fprintf(out,"Studente: %s\nData di nascita:%d/%d/%d\nSesso: %s\n\n",st[i].Nominativo,st[i].dataN.giorno,st[i].dataN.mese,st[i].dataN.anno,st[i].sesso);
  34.                       }
  35.      ("\nL'elenco e' stato salvato correttamente sul file!");
  36.      }
  37.      }
  38.  
  39. void StampaDaVettore(studente st[],int n){
  40.      int i;
  41.      for(i=0;i<n;i++){
  42.                       printf("\nStudente %d" ,i+1);
  43.                       printf("\nCognome e Nome: %s" ,st[i].Nominativo);
  44.                       printf("\nData di nascita: %d/%d/%d ",st[i].dataN.giorno,st[i].dataN.mese,st[i].dataN.anno);
  45.                       printf("\nSesso: %s" ,st[i].sesso);
  46.                       puts("\n");
  47.                       }
  48.      }
  49.      
  50. void StampaDaFile(FILE*out){
  51.      char c;
  52.      if(out==NULL) printf("\nIl file non può essere aperto!");
  53.      else{
  54.           puts("\n\nSTAMPA DA FILE\n");
  55.           fgetc(out);
  56.           while(!feof(out)){
  57.                             putchar(c);
  58.                             fgetc(out);
  59.                             }
  60.           }
  61.      fclose(out);
  62.      }
  63.  
  64. int RicercaPrimo(studente st[],int n){
  65.     int i;
  66.     int position=0;
  67.     while(i<n){
  68.                if(strcmp(st[i].Nominativo,st[i+1].Nominativo)>0){
  69.                                            position=i+1;
  70.                                            }
  71.                i++;
  72.                }
  73.     return position;
  74. }
  75.  
  76. void StampaPrimo(studente st[],int n,int primo){
  77.      printf("\nIl primo nominativo in ordine alfabetico e': %s",st[primo].Nominativo);
  78.      printf("\nLa posizione e': %d" ,primo);
  79.      }
Add Comment
Please, Sign In to add comment