Upload files to "file"
This commit is contained in:
parent
228872bf38
commit
46041ffbd2
|
@ -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 <iostream>
|
||||||
|
#include <cstring>
|
||||||
|
#include <cctype>
|
||||||
|
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;
|
||||||
|
}
|
Loading…
Reference in New Issue