40 lines
881 B
C
40 lines
881 B
C
/*
|
|
Nome: Mario
|
|
Cognome: Montanari
|
|
Classe: 3AIN
|
|
Data: 19/04/2025
|
|
|
|
es07:
|
|
Scrivi un programma che legga da un file "numeri.dat" di 10 righe che rappresenti
|
|
un array di 10 elementi interi, con ogni elemento memorizzato in una riga, e li
|
|
memorizzi in un array.
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
#define SIZE 10
|
|
|
|
int main(void) {
|
|
FILE *file = fopen("numeri.dat", "rb");
|
|
|
|
if (file != NULL) {
|
|
int array[SIZE];
|
|
|
|
if (fread(array, sizeof(int), SIZE, file)) {
|
|
|
|
printf("Elementi dell'array: ");
|
|
for (int i = 0; i < SIZE; i++) {
|
|
printf("%d ", array[i]);
|
|
}
|
|
printf("\n");
|
|
fclose(file);
|
|
|
|
} else {
|
|
perror("Errore durante la lettura del file");
|
|
}
|
|
} else {
|
|
perror("Errore nell'apertura del file");
|
|
}
|
|
|
|
return 0;
|
|
} |