53 lines
865 B
C++
53 lines
865 B
C++
/*
|
|
Nome: Mario
|
|
Cognome: Montanari
|
|
Classe: 3AIN
|
|
Data: 05/04/2025
|
|
|
|
File di Testo a Campi Fissi
|
|
*/
|
|
|
|
#include <iostream>
|
|
|
|
#define SIZE_LINE 1000+1
|
|
|
|
using namespace std;
|
|
|
|
void apriFile(const char * nomeFile);
|
|
|
|
int main(void) {
|
|
apriFile("File Campi Fissi.txt");
|
|
|
|
return 0;
|
|
}
|
|
|
|
void apriFile(const char * nomeFile) {
|
|
FILE * fp = fopen(nomeFile, "rt");
|
|
|
|
if (fp != NULL) {
|
|
char str[SIZE_LINE];
|
|
char nome[SIZE_LINE];
|
|
char cognome[SIZE_LINE];
|
|
char eta[SIZE_LINE];
|
|
int i = 0;
|
|
|
|
while (fgets(str, sizeof(str), fp) != NULL) {
|
|
strncpy(nome, str, 15);
|
|
nome[15] = '\0';
|
|
|
|
strncpy(cognome, str + 15, 20);
|
|
cognome[20] = '\0';
|
|
|
|
strncpy(eta, str + 35, 2);
|
|
eta[2] = '\0';
|
|
|
|
cout << nome << cognome << eta << endl;
|
|
|
|
i++;
|
|
}
|
|
|
|
fclose(fp);
|
|
} else {
|
|
perror("Error (source)");
|
|
}
|
|
} |