Upload files to "file"

This commit is contained in:
Vichingo455 2025-05-07 09:46:20 +00:00
parent 43576bb55e
commit 59eb5b9095
2 changed files with 32 additions and 1 deletions

View File

@ -2,7 +2,7 @@
AUTORE: Manuel Vichi 3^AIN AUTORE: Manuel Vichi 3^AIN
Esercizio 1 File Binari Esercizio 1 File Binari
*/ */
#include <iostream> #include <stdio.h>
#include <stdbool.h> #include <stdbool.h>
using namespace std; using namespace std;
int writeBinary(char * const fileName, size_t elements) { int writeBinary(char * const fileName, size_t elements) {

31
file/es2_binary.cpp Normal file
View File

@ -0,0 +1,31 @@
/*
AUTORE: Manuel Vichi 3^AIN
Esercizio 2 File Binari
*/
#include <stdio.h>
#include <stdbool.h>
using namespace std;
int readBinary(char * const fileName, int buffer[], size_t count) {
FILE* file = fopen(fileName, "rb");
if (file == NULL) {
perror("Errore nell'apertura del file di lettura");
return -1;
} else {
int read = fread(&buffer,sizeof(int),count,file);
fclose(file);
return read;
}
return -1;
}
int main(void) {
char file[] = "file_200.bin";
int arr[100];
size_t count = sizeof(arr) / sizeof(arr[0]);
printf("Valori letti dal file %s: %d\n",file,readBinary(file,arr,count));
printf("Valori letti: ");
for (size_t i = 0; i < count; i++) {
printf("%d ",arr[i]);
}
printf("\n");
return 0;
}