3
After creating create and read I have been having problems in the update and delete code, but currently I have focused more on delete and I am not able to make it delete the entire employee.
Objective: the user inserts the employee ID and he erases all the data concerning the employee.
Unfortunately the result is far from being the request here is the code.
`
FILE *fRead, *fWrite;
char c;
int Delete_Id, temp = 1;
fRead = fopen(FILENAME, "r");
c = getc(fRead);
while (c != EOF) {
printf("%c", c);
c = getc(fRead);
}
rewind(fRead);
printf("\nDelete Staff with ID: ");
scanf("%d", &Delete_Id);
Delete_Id = Delete_Id + 1;
fWrite = fopen("temporary.tmp", "w");
c = getc(fRead);
while (c != EOF) {
c = getc(fRead);
if (c == '\n')
temp++;
if (temp != Delete_Id) {
putc(c, fWrite);
}
}
fclose(fRead);
fclose(fWrite);
remove(FILENAME);
rename("temporary.tmp", FILENAME);
printf("\nThe contents of file after being modified are as follows:\n");
fRead = fopen(FILENAME, "r");
c = getc(fRead);
while (c != EOF) {
printf("%c", c);
c = getc(fRead);
}
fclose(fRead)
From what I understood instead of deleting the data related to the function it just deletes according to the requested line and not his id, otherwise "eats" the first letters presented in txt and adds an ý at the end of the file.
staff variables
struct funcionario {
int codigo1[100], idade[100], numero_telefone[100], numero_dependentes[100];
char nome[100], estado_civil[100];
};
struct funcionario e;
Can someone help?? It’s been several days trying to solve this problem by checking several examples.