Created
November 25, 2013 16:20
-
-
Save vsr/7643984 to your computer and use it in GitHub Desktop.
The program opens a file, prints in a loop and then closes it.
Moving the file to another location, (`mv file.txt file1.txt`) during the loop does not cause any exception or error. At the end of the program, `file1.txt` has the proper output.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| main(){ | |
| printf("Hello there!\n"); | |
| FILE *f = fopen("/tmp/file.txt", "w"); | |
| if(f == NULL){ | |
| printf("Error opening file!\n"); | |
| return 1; | |
| } | |
| int i = 0; | |
| for(i=0; i<20;i++){ | |
| fprintf(f, "%d\n", i); | |
| printf("Printing %d\n", i); | |
| sleep(1); | |
| } | |
| fclose(f); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment