I just tried a new program with a fixed no. of columns.I'm getting a few
This is a prog to create a DBMS with a fixed max no of columns.
problems with output:
when i want the 1st column to be int type and the 2nd column to be of type char,the 1st 3 rows of the 1st column alone is showing some randon junk value.The rest of the output is perfect
I think there should be some problem with the allocation of these 3 places.....
But when i hav 2 columns of int or 2 columns of char,the output is perfect....
db.tbl.col=0;
char reply;
cout<<"\nEnter username:"<<endl;
cin.getline(db.username,20);cin.get();
cout<<"\nEnter the password upto 8 characters,containing alphabets and numbers: "<<endl;
cin.getline(db.password,10);cin.get();
clrscr();
cout<<"\nEnter the name of the table:"<<endl;
cin.getline(db.tbl.tbl_name,20);
fstream f(db.tbl.tbl_name,ios::binary|ios::ate|ios::in);
cout<<"\nEnter the total number of tuples you want :"<<endl;
cin>>db.tbl.row;cin.get();
f.write((char*)&(db),sizeof(db));
do
{
if(db.tbl.col!=c)
{
cout<<"\nEnter name of the field:"<<endl;
cin.getline(db.tbl.field_name[db.tbl.col],20);
f.write((char*)&(db.tbl),sizeof(db.tbl));
cout<<"\nChoose field type:"<<endl
<<"\n1.Int"<<endl
<<"\n2.Char"<<endl
<<"\n3.String"<<endl;
cin>>db.tbl.fld_type[db.tbl.col];cin.get();
db.tbl.col+=1;
f.write((char*)&(db.tbl),sizeof(db.tbl));
cout<<"\nWant another column?"<<endl;
cin>>reply;cin.get();
}
else cout<<"\n\nyou have crossed the column limit..!!";
}while(reply=='y'||reply=='Y');
cout<<endl<<"\nNo of columns: "<<db.tbl.col
<<endl<<"\nNo of rows: "<<db.tbl.row;
}
else if(db.tbl.fld_type[a]==3)
{
cout<<"\nEnter the string:"<<endl;
for(int s=0;s<len;++s)
{
cin>>str[k][a][s];
}
cout<<endl<<"updating "<<k<<" "<<a;
}
f.write((char*)&(db.tbl),sizeof(db.tbl));
}
}
cin.get();
clrscr();
}
void DBMS::disp_tbl()
{
fstream f(db.tbl.tbl_name,ios::binary|ios::in|ios::ate);
if(!f)
{
cerr<<endl<<db.tbl.tbl_name<<"could not be opened for displaying...press <enter>";
cin.get();
exit(1);
}
while(!f.eof())
{
cout<<"\nno of rows : "<<db.tbl.row<<" and columns : "<<db.tbl.col<<endl;
for ( int j=0;j<db.tbl.col;++j)
{
cout<<setw(20)<<db.tbl.field_name[j];
f.read((char*)&db.tbl,sizeof(db.tbl));
}
for(int in=0;in<db.tbl.row;++in)
{
cout<<endl;
for(int i=0;i<db.tbl.col;++i)
{
cout<<setw(20);
if (db.tbl.fld_type[i]==1)
{
if(integer[in][i]!=-200) //-200 is chosen as illegal value
{
cout<<setw(20)<<integer[in][i];
}
}
else if (db.tbl.fld_type[i]==2)
{
if(charac[in][i]!='-') //'-' is chosen as illegal.
{
cout<<setw(20)<<charac[in][i];
}
}