Govt Exams
'a+' mode opens file for reading and appending. New data is added at the end without removing existing content. 'w+' would truncate the file.
rewind(fp) repositions the file pointer to the start of the file. It's equivalent to fseek(fp, 0, SEEK_SET).
feof(fp) returns a non-zero value when EOF (End Of File) is reached, and returns zero when not at EOF.
fputc() writes a single character to the specified file. fgetc() reads a character, fwrite() writes blocks, and fprintf() writes formatted output.
'w+' mode opens a file for both reading and writing. If the file doesn't exist, it creates a new one. If it exists, it truncates the file to zero length.
stdio.h (Standard Input/Output) contains all file handling functions like fopen(), fclose(), fread(), fwrite(), etc.
fread(buffer, size, count, fp) efficiently reads file in manageable chunks. Process each chunk, then read next. This is standard practice for large file handling.
Third parameter is 'whence': SEEK_SET (beginning), SEEK_CUR (current position), SEEK_END (end). Second parameter specifies offset in bytes.
fread() with buffer reads multiple bytes per call, reducing function call overhead. fgetc() makes 100,000 separate calls. fgets() is limited to reading up to newline.
In append mode "a" or "a+", file pointer initially points to end of file for writing. For reading in "a+", you must explicitly seek to read from start.