Since you haven't posted a runnable program I can't actually try it, but I do see some oddities.
The oddest thing is that you seem to be mixing sequential access with random access. You are trying to find the cod with a sequential search (the while loop), but then you fseek to cod*sizeof(f), which is random access (where you jump directly to the correct position). Which is it? Are the cod numbers the 0-based offsets of the records? If so, then you should do something like:
Code:
// ...get cod from user, then...
if (fseek(g, cod * sizeof(f), SEEK_SET) != 0)
printf("Record not found\n");
else if (fread(&f, sizeof(f), 1, g) != 1)
printf("Record could not be read\n");
else {
// ...get the new price from the user, then...
fseek(g, cod * sizeof(f), SEEK_SET);
fwrite(&f, sizeof(f), 1, g);
}
If you mean it to be sequential access (cod is not the record offset), then you need to get rid of the else statement that prints "Nu exista". You don't know if it doesn't exist until after the loop is done.
And when you do find it, the fseek needs to be something like the following in order to move back one record:
Code:
fseek(g, -sizeof(f), SEEK_CUR);