Govt Exams
Mixing write (fwrite - binary) and read (fprintf - formatted text) functions on same data causes mismatch. Binary data won't have format specifiers; misinterpretation results.
fflush(fp) forces buffered output to be written to disk immediately without closing the file. Useful for ensuring data safety before risky operations.
Best solution is allocate larger buffer. If line is 500 chars, use buffer >= 501. Option C partially works but complicates newline handling. fscanf() doesn't automatically handle long lines.
"w" mode opens file for writing and truncates it to zero length if it exists. "r+" doesn't truncate. "a" and "a+" are append modes that don't truncate.
To skip first 10 structures and read 11th: 10 * 32 = 320 bytes from start. Option B (320 bytes) positions pointer at start of 11th structure (320 bytes offset).
fopen() returns NULL pointer on failure. Proper practice is to check: if(fp == NULL) {...error handling...}. Returning -1 is for system calls like open().
fscanf() reads formatted data from file (like scanf() but from file). fgets() reads strings. fread() reads binary data. getc() reads single character.
Without fclose() or fflush(), buffered data remains in memory. If program terminates, that data never reaches disk. System may flush on exit but it's unreliable.
SEEK_END moves pointer relative to end of file. Offset 0 means go to the exact end. SEEK_SET (beginning) and SEEK_CUR (current) are other origin options.
In text mode, fseek() behavior is implementation-dependent due to line-ending conversions (\r\n vs \n). Binary mode provides more predictable fseek() behavior with absolute byte positions.