Prev  Next  Up  Contents

Opening an Existing Database

The iopen_db function is called to open an existing database. It requires a single argument, the name of the database (no extension necessary). The iopen_db function opens two files, the data file with extension DB and the index file with extension IDX. Like the icreate_db function, the iopen_db function returns a pointer to a database object of type Db_Obj. A return value of NULL indicates that an error occurred in attempting to open the existing database.

The following example program opens the existing database named BOOKS. The two database files, BOOKS.DB and BOOKS.IDX, must be present in the current directory for this program to successfully open the database.

#include "isam.h"

int main()                      /* open.c */
    Db_Obj *db;
    char   *db_name = "BOOKS";

    /* open ISAM database */
    db = iopen_db(db_name);
    if (db == NULL) {
        printf("Unable to open database: %s\n", db_name);
        return -1;

    printf("Opened database: %s\n", db_name);

    /* close ISAM database */

    return 0;

Next Page
C/Database Toolchest Description
Product List