Last active
December 3, 2015 17:53
-
-
Save ehermes/fbc8883c0a3231932cc8 to your computer and use it in GitHub Desktop.
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> | |
| #include <errno.h> | |
| #include <unistd.h> | |
| extern int errno; | |
| int main() | |
| { | |
| FILE *fp; | |
| fp = fopen("test_file", "w+"); | |
| perror("fopen returned"); | |
| unlink("test_file"); | |
| perror("unlink returned"); | |
| int nchar = fprintf(fp, "Testing..."); | |
| perror("fprintf returned"); | |
| printf("fprintf wrote %i characters\n", nchar); | |
| char buffer[100]; | |
| rewind(fp); | |
| perror("rewind returned"); | |
| int last = fread(buffer, 1, nchar, fp); | |
| perror("fread returned"); | |
| buffer[last] = 0; | |
| printf("read \"%s\" from file\n", buffer); | |
| fclose(fp); | |
| perror("fclose returned"); | |
| return errno; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
[ehermes@aci-service-1 test]$ ./unlink_test_c
fopen returned: Success
fprintf returned: Success
fprintf wrote 11 characters
rewind returned: Success
fread returned: Success
read "T[▒0" from file
fclose returned: Success
[ehermes@aci-service-1 test]$