Hi everybody,

I'm working on project to my tutorial, it's called Library and basically it's reading data from text file and inserting it in structure. Output part is String Grid. It should be able to sort books alphabetically, add and delete books manualy etc. I'm using Borland C++ Turbo.

Here is the code I came up with so far (btw don't laugh/cry when you see the code I study electrical engineering and this is most likely one semester thing for me)

#include <vcl.h>
#include <string>
#include <sstream>
#pragma hdrstop
#include "Unit3.h"

#pragma package(smart_init)
#pragma resource "*.dfm"
TForm3 *Form3;

typedef struct book
	string title;
	string author;
}   BOOK;

book *library[200];

string _title;
string _author;

vector<string> parts;

int index=0;
int ptr=index-1;

void addBook(string _title, string _author)
	book *my_book;
	my_book = (book*) malloc(sizeof(book));
	my_book->title = _title;
	my_book->author = _author;
	library[ptr=index++] = my_book;

void __fastcall TForm3::Open1Click(TObject *Sender)
if (OpenDialog1->Execute()) {
int i, k, m, n;
int count_lines = 0;
string line;

fstream data(OpenDialog1->FileName.c_str(),ios::in);
while (getline(data, line, '\n')) {
	divide_line(line, parts);

	k = 0;
	for (i = 0; i < count_lines; i++) {
		_title = parts[k];
		_author = parts[k+1];
		void addBook(string _title, string _author);

	for (m = 0; m < count_lines; m++) {
		Form3->StringGrid1->Cells[0][m+1] = library[m].title;
		Form3->StringGrid1->Cells[m+1][0] = library[m].author;

my problem is at the very end, I don't know how to write data in String Grid cells. Error message says: Structure required on left side of . or .* - Actualy I don't know if function addBook works :(

Vector parts contains more information than just a title and author (7 things total), right now I'm using only these two things, so titles are 0,7,14,21 etc. and authors 1,8,15,22.

I hope you can help me or at least point me in right direction. :/

Line 56 is a function prototype, not a function call and needs to be fixed.

On line 19 library is declared to be an array of type pointer to type book. Therefore each library[m] will be a pointer to a book object. Hence to access the members of the book oject being pointed to you would use the -> operator rather than the dot operator. That is, if I've got it figured out right.

line 56: I wanted to do it like this: void addBook(parts[k], parts[k+1]); but I'm getting this error message: Undefined symbol 'parts' ... I don't know where to declare this vector, right now it's on line 24, when I moved it to line 54, there was error on line 48

last cycle after correction:

for (m = 0; m < count_lines; m++) {
   Form3->StringGrid1->Cells[0][m+1] = library[m]->title.c_str();
   Form3->StringGrid1->Cells[m+1][0] = library[m]->author.c_str();

edit: oh my god I finally got it :$ I'm totaly exhausted and I'm thinking little slow. addBook(parts[k], parts[k+1]); We have some progress here, right now program freezes, dunno why.

for (m = 0; m < count_lines; m++) 

Suspect this may be causing array overflow when trying to access element at m + 1 == count_lines, but just a guess based on appearance of code and personal past experience with code snafus.

You are right, thx for helping me. :D