Whats wrong with this code

//---------------------------------------------------------------------------

#include <vcl.h>

#include <fstream.h>
#pragma hdrstop

#include "MainUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
   : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
   //char *acc, *id, *sur, *bal;
   int col = 0;
   int row = 1;
   int idpos, surpos, balpos;
   char acc[20], id[20], sur[20], bal[20];
   string line;

   ifstream file;
   file.open("accounts.txt");

   if(file.good())
   {
       while(!file.eof())
       {
         file >> line;
         idpos = 0;
         balpos = 0;
         surpos = 0;
         for(int i = 0; i < (int)line.length(); i++)
         {
            if(line[i] == '#')
            {
               if(idpos == 0)
               {
                  idpos = i+1;   //10
               }
               else if(surpos == 0)
               {
                  surpos = i+1;   //25
               }
               else
               {
                  balpos = i+1;
               }
            }
         }

         strcpy(acc, line.substr(0, idpos - 1).c_str());
         strcpy(id, line.substr(idpos, surpos - strlen(acc) - 2).c_str());
         strcpy(sur, line.substr(surpos, balpos - (strlen(acc) + strlen(id)-3)).c_str());
         strcpy(bal, line.substr(balpos, idpos - (strlen(acc) + strlen(id) + strlen(sur))).c_str());


         col = 0;
         StringGrid1->Cells[col++][row] = acc;
         StringGrid1->Cells[col++][row] = id;
         StringGrid1->Cells[col++][row] = sur;
         StringGrid1->Cells[col++][row] = bal;

         row++;

         StringGrid1->RowCount++;
       }
   }
   else
   {
      ShowMessage("File Not found");
   }
}
//---------------------------------------------------------------------------
Member Avatar for jencas

What is the problem? What does not work or goes wrong?

First Of All , Please Use Code Tags and Secondly . Specify your Problem

And a Tip: Stop using the same names to both pointers and arrays of the same type.

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.