45 lines
829 B
C++
45 lines
829 B
C++
/*
|
|
Nome: Mario
|
|
Cognome: Montanari
|
|
Classe: 3AIN
|
|
Data: 29/03/2025
|
|
|
|
Data una parola P, stampa in un nuovo file
|
|
tutta la riga in cui è contenuta tale parola.
|
|
*/
|
|
|
|
#include <iostream>
|
|
|
|
#define SIZE_STR 1000+1
|
|
|
|
using namespace std;
|
|
|
|
void creaFile(const char *nomeFileSorgente, const char *nomeFileDestinazione);
|
|
|
|
int main(void) {
|
|
creaFile("leggi.txt", "copia.txt");
|
|
|
|
return 0;
|
|
}
|
|
|
|
void creaFile(const char *nomeFileSorgente, const char *nomeFileDestinazione) {
|
|
FILE *fr = fopen(nomeFileSorgente, "rt");
|
|
|
|
if (fr != NULL) {
|
|
FILE *fw = fopen(nomeFileDestinazione, "wt");
|
|
|
|
if (fw != NULL) {
|
|
char str[SIZE_STR];
|
|
|
|
while (fgets(str, sizeof(str), fr) != NULL) {
|
|
if (strstr(str, "parola") != NULL) {
|
|
fputs(str, fw);
|
|
}
|
|
}
|
|
|
|
fclose(fw);
|
|
}
|
|
|
|
fclose(fr);
|
|
}
|
|
} |