# include /* Description: An example of reading from a file * Author: Katia Bulekovs * Date: May 2022 */ /* Note: * * Various modes of opening a file * * r - Opens an existing file for reading * w - Opens a file for writing. Overwrites existing file.Creates a new one if does not exists. * a - Opens a file for appending. If file does not exists, creates a new one. * r+ - Opens a file for reading and writing. * w+ - Opens a file for reading and writing. Overwrites existing file. If file does not exists, creates a new one. * a+ - Opens a text file for both reading and writing. It creates the file if it does not exist. The reading will start from the beginning but writing can only be appended * * For binary files, add "b" to above modes, e.g: "rb", "wb", etc. */ main() { FILE *fp; char buff[255]; fp = fopen("log.txt", "r"); fscanf(fp, "%s", buff); printf("1 : %s\n", buff ); fgets(buff, 255, (FILE*)fp); printf("2: %s\n", buff ); fgets(buff, 255, (FILE*)fp); printf("3: %s\n", buff ); fclose(fp); }