Last active
July 22, 2016 13:27
-
-
Save multivac61/a8b77adf2f3284336b2f24f6dcd1a0e1 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
// http://stackoverflow.com/questions/38515708 | |
#include <stdio.h> | |
#include <stdlib.h> | |
int main(int argc, char argv[]){ | |
char *filename = "test.db"; | |
int my_int = 42; | |
// First we open file and write to it | |
FILE *file = fopen(filename, "w"); | |
fwrite(&my_int, sizeof(int), 1, file); | |
fclose(file); | |
// Then we read from it | |
my_int = -1; | |
file = fopen(filename, "r"); | |
fread(&my_int, sizeof(int), 1, file); | |
fclose(file); | |
// Should print "Read back 42" | |
printf("Read back %d\n", my_int); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment