From 59eb5b9095949b711c2549a75e527cee728ee2ea Mon Sep 17 00:00:00 2001 From: Vichingo455 Date: Wed, 7 May 2025 09:46:20 +0000 Subject: [PATCH] Upload files to "file" --- file/es1_binary.cpp | 2 +- file/es2_binary.cpp | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 file/es2_binary.cpp diff --git a/file/es1_binary.cpp b/file/es1_binary.cpp index 406a2a3..8df2096 100644 --- a/file/es1_binary.cpp +++ b/file/es1_binary.cpp @@ -2,7 +2,7 @@ AUTORE: Manuel Vichi 3^AIN Esercizio 1 File Binari */ -#include +#include #include using namespace std; int writeBinary(char * const fileName, size_t elements) { diff --git a/file/es2_binary.cpp b/file/es2_binary.cpp new file mode 100644 index 0000000..e2ea065 --- /dev/null +++ b/file/es2_binary.cpp @@ -0,0 +1,31 @@ +/* +AUTORE: Manuel Vichi 3^AIN +Esercizio 2 File Binari +*/ +#include +#include +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; +}