#include #include void read_self() { FILE *file; const char *name = "file_open_close.c"; char buf[120]; file = fopen(name, "r"); if(!file){ perror(name); exit(1); } fgets(buf, 120, file); printf("Read from %s\n%s\n", name, buf); fclose(file); } void write_to_temp() { FILE *file; const char *msg = "Well, this is a surprise...\n"; printf("Creating temporary file!\n"); file = fopen("./tmp", "w"); if(!file){ perror("tmp"); exit(1); } fputs(msg, file); fclose(file); } int main() { read_self(); write_to_temp(); return 0; }