Verifica

#include <stdio.h>
int a,i;
FILE *f1;
FILE *f2;
char nomi[70][55];
char nomiFile[70][55];
int distFile[20];
int dist[20];

void caricArray(){
                    for(i=0;i<20;i++){
                    printf("digita il nome dello studente e la distanza\n");
                    scanf("%s %d",nomi[i],&dist[i]);
                    }
}
void caricaFile(){
     f1=fopen("studenti.txt","w");
     f2=fopen("distanza.txt","w");
     for(i=0;i<20;i++){
                       fprintf(f1,"%s\n",nomi[i]);
                       fprintf(f2,"%d\n",dist[i]);
                       }
     fclose(f1);
     fclose(f2);
     }
void controllo(){
     for(i=0;i<20;i++){
     if(dist[i]>30){
                    printf("%s %d",nomi[i],dist[i]);
                    printf(" attenzione studente molto distante\n");
                    }
     else if(dist[i]<=4){
                    printf("%s %d",nomi[i],dist[i]);
                    printf(" attenzione studente molto vicino\n");
                    }
                    }
                    }
void leggiFile(){
             f1=fopen("distanza.txt","r");
    f2=fopen("studenti.txt","r");
                   for(i=0;i<20;i++){
                   fscanf(f1,"%d",&distFile[i]);
            fscanf(f2,"%s",nomiFile[i]);
                   }
    for(a=0;a<20;a++){
        printf("%s",nomiFile[a]);
        printf(" %d\n",distFile[a]);
    }
}

int main()
{
caricArray();
controllo();
caricaFile();
leggiFile();
system("pause");
}

 

Cattura

Commenti

Posta un commento