#include #include int main() { FILE *fp; int numbers[10]; int i, value; // Initialize and write numbers 1 to 10 for (i = 0; i < 10; i++) { numbers[i] = i + 1; } fp = fopen("data.bin", "wb"); if (fp == NULL) { perror("Error opening file for writing"); return 1; } fwrite(numbers, sizeof(int), 10, fp); fclose(fp); printf("Wrote numbers 1 to 10 to file.\n"); // Reopen file for reading and writing fp = fopen("data.bin", "rb+"); if (fp == NULL) { perror("Error opening file for reading and writing"); return 1; } // Move file pointer to the 5th integer (index 4) fseek(fp, 4 * sizeof(int), SEEK_SET); // Read that integer fread(&value, sizeof(int), 1, fp); printf("Value at position 5 before modification: %d\n", value); // Move pointer back to the same position fseek(fp, 4 * sizeof(int), SEEK_SET); // Modify the 5th integer to 999 value = 999; fwrite(&value, sizeof(int), 1, fp); printf("Modified value at position 5 to 999.\n"); fclose(fp); // Verify modification fp = fopen("data.bin", "rb"); if (fp == NULL) { perror("Error opening file for verification"); return 1; } printf("\nFile contents after modification:\n"); for (i = 0; i < 10; i++) { fread(&value, sizeof(int), 1, fp); printf("%d ", value); } printf("\n"); fclose(fp); return 0; }