59 lines
1.2 KiB
C++
59 lines
1.2 KiB
C++
/*
|
|
Nome: Mario
|
|
Cognome: Montanari
|
|
Classe: 3AIN
|
|
Data: 09/04/2025
|
|
|
|
es07. (copialettere)
|
|
Scrivere un programma che, richiesto da tastiera il nome di un file testo,
|
|
memorizzi i caratteri dell'alfabeto nel file lettere.txt e tutti gli altri
|
|
caratteri in altri_car.txt.
|
|
*/
|
|
|
|
#include <iostream>
|
|
|
|
using namespace std;
|
|
|
|
void apriFile(const char * nomeFileSorgente, const char * nomeFileDestinazione1, const char * nomeFileDestinazione2);
|
|
|
|
int main(void) {
|
|
apriFile("testo.txt", "lettere.txt", "altri_caratteri.txt");
|
|
|
|
return 0;
|
|
}
|
|
|
|
void apriFile(const char * nomeFileSorgente, const char * nomeFileDestinazione1, const char * nomeFileDestinazione2) {
|
|
FILE * fr = fopen(nomeFileSorgente, "rt");
|
|
|
|
if (fr != NULL) {
|
|
FILE * fw1 = fopen(nomeFileDestinazione1, "wt");
|
|
|
|
if (fw1 != NULL) {
|
|
FILE * fw2 = fopen(nomeFileDestinazione2, "wt");
|
|
|
|
if (fw2 != NULL) {
|
|
char chr;
|
|
|
|
while ((chr = fgetc(fr)) != EOF) {
|
|
if (isalpha(chr)) {
|
|
fputc(chr, fw1);
|
|
} else {
|
|
fputc(chr, fw2);
|
|
}
|
|
}
|
|
|
|
fclose(fw2);
|
|
} else {
|
|
perror("Error (destination)");
|
|
}
|
|
|
|
fclose(fw1);
|
|
} else {
|
|
perror("Error (destination)");
|
|
}
|
|
|
|
fclose(fr);
|
|
} else {
|
|
perror("Error (source)");
|
|
}
|
|
} |