From 46041ffbd2e0c162c06cdd7f789a017ec08b2a31 Mon Sep 17 00:00:00 2001 From: Vichingo455 Date: Sat, 29 Mar 2025 08:43:45 +0000 Subject: [PATCH] Upload files to "file" --- file/filtralinee_fauser.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 file/filtralinee_fauser.cpp diff --git a/file/filtralinee_fauser.cpp b/file/filtralinee_fauser.cpp new file mode 100644 index 0000000..7bd06ed --- /dev/null +++ b/file/filtralinee_fauser.cpp @@ -0,0 +1,35 @@ +/* +AUTORE: Manuel Vichi +Scrivere una funzione che accetti come parametri d'ingresso due nomi di file e una parola P e + memorizzi nel secondo file le sole righe del primo che contengono P +*/ +#include +#include +#include +using namespace std; +void filtraLinee(const char* fileNameRead, const char* fileNameWrite, const char* word) { + FILE* file = fopen(fileNameRead,"r"); + if (file != NULL) { + FILE* destination = fopen(fileNameWrite,"w"); + if (destination != NULL) { + char riga[256]; + while (fgets(riga, sizeof(riga),file)) { + if (strstr(riga, word)) { + fputs(riga, destination); + } + } + fclose(destination); + } + else { + perror("Errore nella scrittura del file"); + } + fclose(file); + } + else { + perror("Errore nella lettura del file"); + } +} +int main(void) { + filtraLinee("righe.txt","righeParole.txt","Moodle"); + return 0; +}