K
kimimaro
hi below is my save function that is used to placed data from the C program
to a text file for future usage.
void save()
{
FILE *save;
int i = 0;
save=fopen("employeerecord.txt", "a+");
do
{
if(strcmp(record.ID, "")!=0)
{
if(i!=0)
fprintf(save, "\n");
fprintf(save, "%s %s %s %s %s ", record.ID, record.Name,
record.Name2, record.Department[storage], record.Post[rank]);
}
else
{
break;
}
i++;
}while(i<500);
fclose(save);
}
There was no problem for me to save the first employee and the second but
when adding the 3rd employee data, this is what appears in the text file
:
1121 sonia cooling Management Maid 1121 sonia cooling Management Maid
1331 mustapha jamal Management Office_Boy 1121 sonia cooling Management
Maid
1121 sonia cooling Management Maid
1331 mustapha jamal Management Office_Boy
1111 cheng kahhin Administration Chief_Executive_Officer
Sonia is the 1st employee I add, mustapha second and cheng the third. My
data are ID firstname secondname department post and it seems the 1st and
second loops before going to the third pls help if the problem is in the
save function if not its in the add_function but I want to make sure if
its the save function
to a text file for future usage.
void save()
{
FILE *save;
int i = 0;
save=fopen("employeerecord.txt", "a+");
do
{
if(strcmp(record.ID, "")!=0)
{
if(i!=0)
fprintf(save, "\n");
fprintf(save, "%s %s %s %s %s ", record.ID, record.Name,
record.Name2, record.Department[storage], record.Post[rank]);
}
else
{
break;
}
i++;
}while(i<500);
fclose(save);
}
There was no problem for me to save the first employee and the second but
when adding the 3rd employee data, this is what appears in the text file
:
1121 sonia cooling Management Maid 1121 sonia cooling Management Maid
1331 mustapha jamal Management Office_Boy 1121 sonia cooling Management
Maid
1121 sonia cooling Management Maid
1331 mustapha jamal Management Office_Boy
1111 cheng kahhin Administration Chief_Executive_Officer
Sonia is the 1st employee I add, mustapha second and cheng the third. My
data are ID firstname secondname department post and it seems the 1st and
second loops before going to the third pls help if the problem is in the
save function if not its in the add_function but I want to make sure if
its the save function