1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
bool PhoneBook::insertPersonInTheFileC(const char * const name,
const char * const surname,
const char * const street,
const char * const number,
const char * const filePath)
{
try
{
file1 = fopen(filePath, "a");//file1 was declared before as FILE * file1;
fputs ("Hello File!", file1);
fputs("-> Name: ", file1);
fputs(name, file1);
fputs("\n", file1);
fputs("-> Surname: ", file1);
fputs(surname, file1);
fputs("\n", file1);
fputs("-> Street: ", file1);
fputs(street, file1);
fputs("\n", file1);
fputs("-> Phone number: ", file1);
fputs(number, file1);
fputs("\n**************************************************************\n", file1);
cout << "Data inserted successfully.\n";
fclose(file1);
}
catch(...)
{
cerr << "ERROR: impossible to insert data in the file. Restry!\n";
}
}
|