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? 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
}
Aucun commentaire:
Enregistrer un commentaire