Last active
August 29, 2015 14:02
-
-
Save gsathya/4421612211fb752ea6fb 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<unistd.h> | |
| int main (int argc, char *argv[]) | |
| { | |
| FILE *fp; | |
| char test_buf[30]; | |
| fp = fopen("sdltest", "wb+"); | |
| if (!fp) { | |
| printf("Could not open file\n"); | |
| return 0; | |
| } | |
| if (fwrite("1234567890", 10, 1, fp) != 1) { | |
| printf("Could not write to file\n"); | |
| goto error; | |
| } | |
| fclose(fp); | |
| fp = fopen("sdltest", "ab+"); | |
| if (!fp) { | |
| printf("Could not open file\n"); | |
| return 0; | |
| } | |
| if (fwrite("1234567890", 10, 1, fp) != 1) { | |
| printf("Could not write to file\n"); | |
| goto error; | |
| } | |
| fseek(fp, 0, SEEK_SET); | |
| fread(test_buf, 20, 1, fp); | |
| printf("Read %s\n", test_buf); | |
| fseek(fp, -7, SEEK_END); | |
| long len = ftell(fp); | |
| if (len != 13) { | |
| printf("Could not seek correctly\n"); | |
| printf("[DEBUG] len == %lu\n", len); | |
| goto error; | |
| } | |
| error: | |
| fclose(fp); | |
| unlink("sdltest"); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment