1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
int file_reader()
{
DATA d;
ifstream infile("books.txt", ios::in);
if (infile.is_open())
{
while (!infile.eof())
{
for (int row = 1; row < 100; row++)
{
cout << row << ". ";
char line[200];
cin.ignore();
cin.getline(line, 200, '\n');
char* column = strtok(line, ",");
while(column)
{
cin >> d.isbn_code;
column = strtok(NULL, ",");
cin.getline(column, 50);
strcpy(d.author,column);
column = strtok(NULL, ",");
cin.getline(column, 100);
strcpy(d.title, column);
column = strtok(NULL, ",");
cin.getline(column, 50);
strcpy(d.publisher, column);
column = strtok(NULL, ",");
cin >> d.year_published;
column = strtok(NULL, ",");
cin >> d.quantity;
column = strtok(NULL, ",");
cin >> d.price;
column = strtok(NULL, ",");
cin >> d.rack;
column = strtok(NULL, ",");
cin >> d.level_no;
}
cout << d.isbn_code << "," << d.author << "," << d.title << ","
<< d.publisher << "," << d.year_published << "," << d.quantity << ","
<< d.price << "," << d.rack << "," << d.level_no;
} cout << endl;
} infile.close();
}
else
cout << "File is not open\n";
return 0;
}
|