# include /* Description: An example of writing into 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; fp = fopen("log.txt", "w+"); fprintf(fp, "First line: Using fprintf to output a line.\n"); fputs("Second line: Using fputs to output a second line.\n", fp); fclose(fp); }