This is a homework project where user interacts with a database of people that have data such as a number, street name etc. the which data resides in a text file.
Some menu options require the program to read or manipulate that data, for example a Display option. I've done this by opening an fstream and putting the data into a temporary array that has for data type the pre-declared struct resident.
//reopen file
fstream listeResidents1;
listeResidents1.open("listeResidents.dat",ios::out|ios::in|ios::binary);
//Create a temporary array of objects resident for manipulation
resident tabRes1[nombreResid-1];
//Insertion des objets resident du registre dans le tableau temporaire
for (int h = 0;h < nombreResid;h++)
{
listeResidents1.seekg((h)*sizeof(resident));
listeResidents1.read(reinterpret_cast<char*>(&tabRes1[h]),sizeof(resident));
}
listeResidents1.close();
My Display() function does this^^^, then uses a for loop to go through each object in the array and display all of their attributes. However the very last entry has its penultimate string missing some characters and the last variable, a float, set to 0 (which means it was also truncated) and I can't figure out why. Does anyone have any idea why this happens?
For a visual example, last entry was successfully written to file with these attributes:
int numero: 4
[the other,correctly displayed attributes here]
char rue[30]: queen
float superf: 80
when displayed the last entry would display
numero: 4
[the other,correctly displayed attributes here]
rue: que
superf: 0
If I add another entry, it is the one truncated while 4 is now displayed correctly...
Edit: here is the struct.
struct resident
{
int numero;
char nom[30];
char prenom[30];
int numciv;
char rue[30];
float superf;
};