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<fstream.h>
#include <string>
#include <sstream>
#include<vector>
#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')) {
++count_lines;
divide_line(line, parts);
}
data.close();
k = 0;
for (i = 0; i < count_lines; i++) {
_title = parts[k];
_author = parts[k+1];
void addBook(string _title, string _author);
k=k+7;
}
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. :/