Reading from A file

Once the file has been opened for reading using fopen( ), the file’s contents are brought into memory and a pointer points to the very first character. To read the file’s contents from memory there exists a function called fgetc( ).

ch = fgetc ( fp ) ;

fgetc( ) reads the character from current pointer position, advances the pointer position so that it now points to the next character, and returns the character that is read, which we collected in the variable ch. Note that once the file has been opened, we refer to the file through the file pointer fp.

Writing to A File

The fputc( ) function is similar to the putch( ) function, in the sense that both output characters. The file signified by ft. the writing process continues till all characters from the source file have been written to the target file, following which the while loop terminates.We have already seen the function fgetc( ) which reads characters from a file.

The reference site for this content is