i got it..i intent to to keep reading the file whenever you want to access the data
and
Code:
void modifyStaff() {
char ans, cont, name[25], position[20];
int i = 0, pCount, modiCount = 0, found, id;
int salary;
staff P[20];
FILE*fp;
fp = fopen("staff.dat", "rb");
while (fread(&P[i], sizeof(staff), 1, fp))
i++;
pCount = i;
fclose(fp);
do {
printf("\nEnter ID of the Staff to be modified : ");
rewind(stdin);
scanf("%d", &id);
found = 0;
printf("\nID NAME POSITION SALARY \n");
printf("====== ====== ========== ======= \n");
for (i = 0; i < pCount; i++) {
if (id == P[i].id)
{
found = 1;
printf("%-18d %-10s %-10s %-10d \n",
P[i].id, P[i].name, P[i].position, P[i].salary);
printf("\n Updated Name:");
rewind(stdin);
scanf("%[^\n]", &name);
printf("\n Updated Position:");
rewind(stdin);
scanf("%[^\n]", &position);
printf("\n Updated salary:");
rewind(stdin);
scanf("%d", &salary);
printf("Confirm to Modify (Y=yes)? ");
rewind(stdin);
scanf("%c", &ans);
if (toupper(ans) == 'Y') {
P[i].id = id;
strcpy(P[i].name, name);
strcpy(P[i].position, position);
P[i].salary = salary;
modiCount++;
}
printf("Updated Staff Records:\n");
printf("\nID NAME POSITION SALARY\n");
printf("======== ========= =========== ========\n");
printf("%-18d %-10s %-10s %-10d", P[i].id, P[i].name, P[i].position, P[i].salary);
}
}
if (!found)
printf("NO record founded with this ID\n");
printf("Any more record to modify?(Y=yes)?");
rewind(stdin);
scanf("%c", &cont);
} while (toupper(cont) == 'Y');
fp = fopen("staff.dat", "wb");
for (i = 0; i < pCount; i++)
fwrite(&P[i], sizeof(staff), 1, fp);
fclose(fp);
printf("\n\t%d Record(s) modified.\n\n", modiCount);
}
i would like to ask where can i put the parameter, i doing an assigment and the parameter is compulsory to add but i dunno where to add