Hi everyone,
I'm currently doing a group assignment on C, and i'm kind of stuck in my part of the work.
So, one of my colleagues is receiving user input, and then saving it in a file, and my part consists of asking the user for input on which part of the data he wants to edit, edit it, and save into a file again.
But i'm stuck on the part of searching the file for the part I need to edit.
I'm using fread to read the file content into the screen (struct with 3 ints and 2 char arrays).
The objective is to keep the student_number, but change the other parts, but for the life of me, I can't understand how to get fseek to where i want it to be.Code:struct studentdata{
int student_number;
char student name[40];
int student_id;
char student_address[60];
int phone_number;
};
But when i use fseek, Which in my ingenuity should change the pointer location, it doesn't seem to do anything.Code:printf("Please input the student number you want to edit:");
scanf("%d",&edit_student);
Or a few other attempts i've tried, but have already removed from the file.Code:fseek(p,(edit_student)*sizeof(struct studentdata),SEEK_SET);
or for example:
fseek(p,sizeof(struct studentdata)*(edit_student-1),SEEK_SET);
And then try to edit the data, it still edits the last data it printed in the screen (the one that's still in the buffer).
Am i using the right logic at least?
Sorry, It's my second time having C classes, and just like 12 years ago, i still can't get the hang of it :(
Thanks for the help