typedef struct
{
int isbn_code, year_published, quantity, rack, level_no;
char author[50], title[100], publisher[50];
double price;
}DATA;
Shown above is my typedef struct. And when i debug, it only shows "1. ". So here is my code. Please tell me what's wrong and what do i need to do to make it execute properly. I'm just trying to read from a text file and categorize them into different members of structure.
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;
}