Govt. Exams
Entrance Exams
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.
Third parameter is 'whence': SEEK_SET (beginning), SEEK_CUR (current position), SEEK_END (end). Second parameter specifies offset in bytes.
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.
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.
fprintf() writes formatted data to file (like printf() but to file). fscanf() reads formatted data. fwrite() writes binary data. fputs() writes strings.