/* Nome: Mario Cognome: Montanari Classe: 3AIN Data: 07/04/2025 File di Testo CSV con l'uso di strtok() */ #include #include #define SIZE_LINE 1000+1 using namespace std; void apriFile(const char * nomeFile); int main(void) { apriFile("File CSV.txt"); return 0; } void apriFile(const char * nomeFile) { FILE * fp = fopen(nomeFile, "rt"); if (fp != NULL) { char *ptr; char str[SIZE_LINE]; char nome[SIZE_LINE]; char cognome[SIZE_LINE]; int i = 0; while (fgets(str, sizeof(str), fp) != NULL) { ptr = strtok(str, " "); strcpy(nome, ptr); cout << nome << " "; ptr = strtok(NULL, ";"); strcpy(cognome, ptr); cout << cognome << " "; ptr = strtok(NULL, ";"); cout << atoi(ptr) << endl; i++; } fclose(fp); } else { perror("Error (soure)"); } }