hey guys its 1.30 am and I just can't see where the problem here !
the text file contains just brand , model and price, please help !
#include<iostream>
#include<fstream>
using namespace std;
struct computer{
char * brand ;
char * model;
double price;
};
void readin(computer * , int );
void printf(computer * );
int main ()
{
computer * pc ;
computer * temp;
int size;
char filename [30];
cout<< " please enter the file name : "<<endl;
cin>>filename;
readin(pc, size);
printf(pc);
delete [] pc;
delete [] temp;
system("pause");
return 0;
}
// reading function
void readin(computer * , int )
{
computer * pc ;
computer * temp;
int size;
ifstream fin;
char filename [30];
fin.open(filename);
fin>>size;
pc = new computer[size];
temp = pc;
for (int i =0; i<size; i++)
{
(*temp).brand = new char [15];
(*temp).model = new char [15];
fin>>(*temp).brand>>(*temp).model>>(*temp).price;
temp++;
}
fin.close();
temp = pc;
for ( int i = 0; i<size; i++)
{
delete [] (*temp).brand;
delete [] (*temp).model;
temp++;
}
delete [] pc;
delete [] temp;
}
// printing function
void printf(computer * )
{
computer * pc ;
computer * temp;
int size;
for(int i= 0; i<size; i++)
{
cout<<"brand:"<<(*temp).brand<<"model:"<<(*temp).model<<"price:"<<(*temp).price <<endl;
temp++;
}
temp = pc;
for ( int i = 0; i<size; i++)
{
delete [] (*temp).brand;
delete [] (*temp).model;
temp++;
}
temp = pc;
delete [] pc;
delete [] temp;
}