Page Actions
Wiki Actions
User Actions
Submit This Story

Simple gdbm demo

The Code

/*
  Simple gdbm example.
 
  This is how you compile
 
      $ gcc gdbm_ex1.c -lgdbm -o gdbm_ex1
 
  Format of the datum struct:
 
      typedef struct {
                 char *dptr;
                 int  dsize;
              } datum;
*/
#include 
#include 
 
int main (void)
{
  GDBM_FILE dbf;
  datum key = { "testkey", 7 };     /* key, length */
  datum value = { "testvalue", 9 }; /* value, length */
  datum content;
 
  printf ("Storing key-value pair... ");
  dbf = gdbm_open ("test", 0, GDBM_NEWDB, 0644, 0);
  gdbm_store (dbf, key, value, GDBM_INSERT);
  gdbm_close (dbf);
 
  dbf = gdbm_open ("test", 0, GDBM_READER, 0644, 0);
  content = gdbm_fetch(dbf, key);
  printf("\n Output %s\n",content.dptr);
  printf ("done.\n");
  gdbm_close (dbf);
 
  return 0;
}

Discussion

Enter your comment
 
 
blog/2009/10/simple_gdbm_demo.txt · Last modified: 2009/10/01 00:00 (external edit)     Back to top
Recent changes RSS feed Creative Commons License Powered by PHP Driven by DokuWiki