Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define dim 30
- typedef struct{char nomeEsame[20];
- int votoEsame;
- } esame;
- void scrivi(esame a[],int*m);
- void visualizza(esame a[],int m);
- void salvasufile(FILE*out,esame a[],int m);
- void leggifile(FILE*out);
- void ordina(esame a[],int m);
- void stampavettore(esame a[],int m);
- int main()
- {
- esame esami[dim];
- int n;
- FILE*fp;
- scrivi(esami,&n);
- visualizza(esami,n);
- fp=fopen("verbaleanzi.txt","w");
- salvasufile(fp,esami,n);
- fclose(fp);
- fp=fopen("verbaleanzi.txt","r");
- leggifile(fp);
- fclose(fp);
- ordina(esami,n);
- stampavettore(esami,n);
- system("PAUSE");
- return 0;
- }
- void scrivi(esame a[],int*m)
- {
- int n;
- printf("quanti esami vuoi inserire? ");
- scanf("%d",&n);
- getchar();
- printf("\ninserisci esami\n\n");
- int i;
- for(i=0;i<n;i++)
- {
- printf("insersci nome esame\n");
- gets(a[i].nomeEsame);
- printf("unserisci voto esame\n");
- scanf("%d",&a[i].votoEsame);
- printf("\n");
- getchar();
- }
- *m=n;
- }
- void visualizza(esame a[],int m)
- {
- printf("gli esami inseriti sono\n\n");
- int i;
- for(i=0;i<m;i++)
- {
- printf("nome esame: %s\n",a[i].nomeEsame);
- printf("voto esame: %d\n",a[i].votoEsame);
- printf("\n");
- }
- }
- void salvasufile(FILE*out,esame a[],int m)
- {
- if(out==NULL)
- {
- printf("errore nell'apertura del file in lettura\n");
- }
- else
- {
- printf("\nSALVATAGGIO SU FILE IN CORSO....\n\n");
- int i;
- for(i=0;i<m;i++)
- {
- fprintf(out,"nome esame: %s\n",a[i].nomeEsame);
- fprintf(out,"voto esame: %d\n",a[i].votoEsame);
- fprintf(out,"\n");
- }
- }
- }
- void leggifile(FILE*out)
- {
- if(out==NULL)
- {
- printf("errore nell'apertura del file\n");
- }
- else
- {
- char c;
- printf("******CONTENUTO DEL FILE******\n\n");
- c=fgetc(out);
- while(!feof(out))
- {
- putchar(c);
- c=fgetc(out);
- }
- }
- }
- void ordina(esame a[],int m)
- {
- esame app;
- int i,j;
- for(i=1;i<m;i++)
- {
- app=a[i];
- j=i-1;
- while(j>=0 && a[j].votoEsame>app.votoEsame)
- {
- a[j+1]=a[j];
- j--;
- }
- a[j+1]=app;
- }
- }
- void stampavettore(esame a[],int m)
- {
- printf("\n******VETTORE ESAMI ORDINATO RISPETTO AL CAMPO VOTO******\n\n");
- int i;
- for(i=0;i<m;i++)
- {
- printf("nome esame: %s\n",a[i].nomeEsame);
- printf("voto esame: %d\n",a[i].votoEsame);
- printf("\n");
- }
- }
Add Comment
Please, Sign In to add comment