Search code examples
cfseek

using fseek() to find position entered by user


I need to ask the user for an ID Number, and then use the function fseek() to find the position of the ID Number entered by the user, and then be able to modify the records. I have something like this:

printf("Enter ID Card Number: \n");
scanf("%s", editCust.idNumber);
fseek(custFile, (editCust.idNumber -1)*sizeof(struct customer), SEEK_SET);

Solution

  • No.

    First, substitute:

    scanf("%s", editCust.idNumber);

    for

    scanf("%d", &editCust.idNumber);

    %s is for string values and %d is for decimal values.

    A good source of formats can be found here.