I am writing a simple program where it records data for employees. I have a struct array that is initialized to null but it's displaying "0" instead of just blank.
My code:
#define SIZE 4
struct EmployeeData {
int id;
int age;
double salary;
};
struct EmployeeData emp[SIZE] = { { { 0 } } };
[ ... ]
case 4: // Remove Employee
printf("Remove Employee\n");
printf("===============\n");
printf("Enter Employee ID: ");
scanf("%d", &j);
do {
for (i = 0; i < SIZE; i++) {
if (j == emp[i].id) {
printf("Employee %d will be removed\n", j);
emp[i].id = '\0';
emp[i].age = '\0';
emp[i].salary = '\0';
end = 1;
}
}
} while (end != 1);
break;
When I display the struct array it displays something like:
EMP ID EMP AGE EMP SALARY
====== ======= ==========
112 24 8999.99
113 29 7999.99
114 88 6999.99
0 0 0.00
Even when I remove/delete an employee, it would just replace it with 0 instead of leaving it blank. So when I delete a employee, for example id #113, I just want it to be like:
EMP ID EMP AGE EMP SALARY
====== ======= ==========
112 24 8999.99
114 88 6999.99
Instead of:
EMP ID EMP AGE EMP SALARY
====== ======= ==========
112 24 8999.99
0 0 0.00
114 88 6999.99
0 0 0.00
I have tried everything I saw online and nothing helped me. Thank you in advance!
emp[i].salary = '\0';you are assigning these values to 0 and not to "blank"? Anintand adoublehave no "blank" representation in C.do/while, just add abreakstatement when the employee is found, if you can assume there are no duplicate entries.