Lexical Analyzer in c++

i want to read a file which in first line contains rows and in second line columns and on its basis allocate dynamic array after second line transition table exists in file having ascii values of 128 characters on keyboard and last index 128 should store accepted state with some number like 101 and rejected state with -1 and then store this transition table in dynamically allocated array What am i doing wrong in this code correct me?
#include "iostream"
#include "fstream"
#include "string"


using namespace std;

int main()
{
int line=0;
string l;
int rows=5;
int cols=6;
int count=0;

int **a=new int*[rows];// Dynamic array creation

for (int k=0;k<rows;k++)
{
a[k]=new int[cols];
}
ifstream myfile ("23.txt"); // Reading file

if(myfile.is_open())
{
while(!myfile.eof() )
{
myfile>>l;
cout << l;


if ((l =="\n")||(l=="\r"))
{
line++;

}

if (line ==2)
{

for (int i=0;i<rows;i++)//storing transition table in dynamically creaed array

{
for(int j=0;j<cols;j++)
{
a[i][j]=(int)l[j];
cout << l[j] << '\t';
count++;
}
}

}
}


myfile.close();//close the file
}
Last edited on
it looks like you wanted a dynamic array size but you made those constants in the program which may be just to get started for debugging purposes but its unclear so you may need to check that your hard coded dimensions are correct for the file but if that is just debugging getting started values its ok so another issue is that it appears to only read one line ever you may have meant to read a line each time in the loop that assigns the array and wow punctuation can be useful.
Topic archived. No new replies allowed.