Problem: go though a file and find the corresponding last name, with corresponding info and DISPLAY!!
I'm going crazy with figuring out that program.
The process is more than simple: get the user to put in employee info (ID, last name, first name, dept, and salary), and store those in a file.
Here's what I got:
Code:
void newEmployee(EMP *emp, FILE *empfPtr) {
static int i=0;
int i_temp=0;
char s_temp[MAXLEN];
float f_temp=0;
rewind(empfPtr);
printf ("Enter new employee ID no.:");
scanf("%d", &i_temp);
validateID(i_temp, emp);
emp[i].ID = i_temp;
fprintf(empfPtr, "%d", emp[i].ID);
puts("Enter employee last name:");
scanf("%s", emp[i].last_name);
upperCase(emp[i].last_name);
fprintf(empfPtr, "%d", emp[i].last_name);
puts("Enter employee first name:");
scanf("%s", emp[i].first_name);
upperCase(emp[i].first_name);
fprintf(empfPtr, "%d", *emp[i].first_name);
puts("Enter employee department:");
scanf("%s", s_temp);
upperCase(s_temp);
validateDept(s_temp);
strcpy(emp[i].dept, s_temp);
fprintf(empfPtr, "%s", emp[i].dept);
puts("Enter employee salary:");
scanf("%f", &f_temp);
validateSalary(f_temp);
emp[i].salary = f_temp;
fprintf(empfPtr, "%f", emp[i].salary);
i++;
puts("Next command (0 to print menu): ");
}
this seems to work fine.
Now, there's an option that allows the user to view employee info (once entered), and here's what I've got:
Code:
void displayInfo(EMP *emp, FILE *empfPtr) {
int i = 0;
int j = 0;
char temp[MAXLEN];
puts("Enter employee last name (display info):");
scanf("%s", temp);
fgets(emp[i].last_name, NAMELEN, empfPtr);
while(emp[i].last_name != temp) {
i++;
if(i == SIZE) {
puts("No corresponding employee last name.");
puts("Next command (0 to print menu): ");
}
fgets(emp[i].last_name, NAMELEN, empfPtr);
}
if(emp[i].last_name == temp)
strcpy(emp[i].last_name, temp);
fscanf(empfPtr, "%d", emp[i].ID);
printf("Employee ID: %d\n", emp[i].ID);
fscanf(empfPtr, "%s", emp[i].last_name);
printf("Employee last name: %s\n", emp[i].last_name);
fscanf(empfPtr, "%s", emp[i].first_name);
printf("Employee first name: %s\n", emp[i].first_name);
fscanf(empfPtr, "%d", emp[i].dept);
printf("Employee department: %s\n", emp[i].dept);
fscanf(empfPtr, "%f", emp[i].salary);
printf("Employee salary: $%.2f\n", emp[i].salary);
puts("Next command (0 to print menu): ");
return;
}
this definitely doesn't work!! I feel like I have no idea what I'm doing, and it's getting really frustrating... cause I'm just guessing all of that.
Can anyone help me out here?