Skip to content

Instantly share code, notes, and snippets.

@multivac61
Last active July 22, 2016 13:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save multivac61/a8b77adf2f3284336b2f24f6dcd1a0e1 to your computer and use it in GitHub Desktop.
Save multivac61/a8b77adf2f3284336b2f24f6dcd1a0e1 to your computer and use it in GitHub Desktop.
// 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