i have a training application which incorporates c/c++ and raima database(a database system written in c)
i was able to insert some data in it but i cant read from it. the files are as follows:

Books.cpp :

#include "Booksh.h"
#include <iostream>
#include <string>

using namespace std;
info bookrec;

Books::Books(void)
{
}

Books::~Books(void)
{
}

void Books::ListAllBooks()
{
	 int book_count = 0;
   int status;
  
   cout << "List of books in our library:" << endl;

   for (status = d_keyfrst(INFO_TITLE);
        S_OKAY == status;
        status = d_keynext(INFO_TITLE))
   {
      d_recread(&bookrec);

      ++book_count;
      
      //cout << bookrec.id_code << ": " << bookrec.info_title << endl;
   }

   cout << "End of list. Total: " << book_count << endl;

   return;
}

void Books::BookByID()
{
	cout<< "bookbyid" << endl;
}

void Books::UpdateBook()
{
	cout<< "updatebook" << endl;
}

void Books::DeleteBook()
{
	cout<< "deletebook" << endl;
}

int Books::InsertBook()
{
    cout << "id_code :" << endl;
    cin >> bookrec.id_code;
	cout << "info_title :" << endl;
	cin >> bookrec.info_title;
	cout << "author :" << endl;
	cin >> bookrec.author;
	cout << "publisher :" << endl;
	cin >> bookrec.publisher;
	cout << "pubdate :" << endl;
	cin >> bookrec.pub_date;
	cout << "infotype :" << endl;
	cin >> bookrec.info_type;
	
	d_fillnew(INFO, &bookrec);
    cout << "successful" << endl;
	return 5;
}

start.cpp

#include "Booksh.h"
#include <iostream>
using namespace std;
void menu();
int main()
{

	int task = 0;
    d_open("books", "o");
    Books Book;
	
	while(task != -1)
	{
		menu();
		cin>>task;
		
		switch(task)
		{
		case 1:
			Book.ListAllBooks();
			break;
		case 2:
			Book.BookByID();
			break;
		case 3:
			Book.UpdateBook();
			break;
		case 4:
			Book.DeleteBook();
			break;
		case 5:
			Book.InsertBook();
			break;
        case -1:
			d_close();
			exit(0);
			break;
		default:
			cout<< "Not a valid command" << endl;
			break;
		}
	}
	return 0;
}
void menu()
{
cout << "please choose your task below" << endl;
	cout << "type 1 to list all books" <<endl;
	cout << "type 2 to find a book" <<endl;
	cout << "type 3 to update a book" <<endl;
	cout << "type 4 to delete a book" <<endl;
	cout << "type 5 to add a book" <<endl;
	cout << "type -1 to quit application" <<endl;

}

books.h :

/* db_VISTA Version: 3.64 */

/* database books record/key structure declarations */

#ifndef __books_H_INCLUDED__
#define __books_H_INCLUDED__

struct info {
   char  id_code[16];
   char  info_title[80];
   char  author[32];
   char  publisher[32];
   char  pub_date[12];
   int  info_type;
};

/* record, field and set table entry definitions */

/* File Id Constants */

/* Record Name Constants */
#define INFO 10000

/* Field Name Constants */
#define ID_CODE 0L
#define INFO_TITLE 1L
#define AUTHOR 2L
#define PUBLISHER 3L
#define PUB_DATE 4L
#define INFO_TYPE 5L

/* Set Name Constants */

#endif /* __books_H_INCLUDED__ */

and finally Booksh.h :

//#pragma once

extern "C"
{
   #include <vista.h>
   #include "books.h"
}
#include <string>
using namespace std;
class Books
{
public:
	Books(void);
public:
	~Books(void);
public:
	void ListAllBooks();
public:
	void BookByID();

public:
	void UpdateBook();
public:
	void DeleteBook();
public:
	int InsertBook();
};

Do you have any idea about the problem?

yeah we are totally free if suffering means freedom, freaking c and its lovers have nothing to say now, no documentation no nothing whereas if this problem occured in one of microsoft products i could have already found my solution. i dont like different cultures i dont like different languages, i dont understand what kind of freedom or color it is not to communicate with each other. it wouldnt bother me at all if there was only microsoft. i hate unix supporters as well, as well as the open source supporters, where are you guys when i have a problem on your platform?

Anyway although i cant find documentation, i was able to solve the problem. i didnt know that database refreshes it self after i add a record whereas it doesnt when i deleted a record, it is just marked.

What is d_recread?..Where is it?..

What is d_recread?..Where is it?..

it is created when you compile the raima database. this is from 30 years back. database is written in pure c and you compile the database then it provides an interface or an API for you to work with it. the total thing is so old but i have to back up this system. that is why i am training these. and d_recread is part of that old API, made available after compilation.

Solved or not..??..
Use cin.getline(name,size) to read a string..To display..Simply..

d_recread(&bookrec);
for (status=d_keyfrst(INFO_TITLE);status==S_OKAY;status=d_keynext(INFO_TITLE))
{
   //...
}
//...

yeah as i marked, it is solved, i just didnt know that database refreshed it self after insertion whereas it didnt after deletion.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.