Hey everybody, I want to be able to read lines of data from a text document and store it in a array and output the array in a file. does know how to skip whitespace when reading data from a file. The data i want to read is below
And here is the code i have done so far. what i am doing wrong.Forsyth, Frederick ;The fist of god ;A;102391
Follett, Ken ;The pillars of the earth ;A;103795
Francis, Clare ;Wolf winter ;A;112424
Smith, Wilbur ;A falcon flies ;A;151395
Forsyth, Frederick ;The day of the jackal ;A;159151
Blackmore, R.D. ;Lorna Doone ;A;193292
Smith, Wilbur ;Men of men ;A;292351
Smith, Wilbur ;The angels weep ;A;482315
James, P.D. ;Cover her face ;D;144371
James, P.D. ;Devices and desires ;D;193395
Kellerman, Faye ;Stone kiss ;D;434517
James, P.D. ;The skull beneath the skin ;D;439518
Kelly, Jim ;The water clock ;D;543951
Hoag, Tami ;Dark horse ;D;664333
Cookson, Catherine ;The silent lady ;R;151611
Cookson, Catherine ;Kate hannigans girl ;R;165163
Thompson, E.V. ;The lost years ;R;165213
Steel, Danielle ;The cottage ;R;177516
Binchley, Maeve ;Quentins ;R;261561
Alcott, Louisa ;Little women ;R;395104
Cookson, Catherine ;Rosie of the river ;R;512843
Asimov, Isaac ;Foundation ;S;165108
Barker, Clive ;Imajica ;S;172816
Barker, Clive ;The great and secret show ;S;174427
Barker, Clive ;Weaveworld ;S;282118
Clarke, Arthur C ;2001 A space odessy ;S;294561
Asimov, Isaac ;Foundation and empire ;S;313178
Asimov, Isaac ;Second foundation ;S;549201
Code:#include <string> #include <fstream.h> #include <assert.h> #include <iostream> #include <stdlib.h> using namespace std; const int max = 5000; struct book // holds book details { string secondname; string firstname; string title; char cat; int bnumber; }; int main (int argc, char* argv[]) { assert (argc >= 1); // type book data filename ifstream accfile (argv[1]); //opens book data book b[max]; int counter = 0; do { accfile >> b[counter].secondname >> b[counter].firstname >> b[counter].title >> b[counter].cat >> b[counter].bnumber //stores it in array b if (accfile) { counter++; } } while (accfile && counter < max); cout << counter << " read" << endl; accfile.close(); ofstream oaccfile("search.txt"); // write data to a new file for ( int i = 0; i < counter; i++ ) { oaccfile << b[i].secondname << " " << b[i].firstname << " " << b[i].title << b[i].cat << " " << b[i].bnumber << endl; } oaccfile.close() ; cout << "Output file created: Seacrh.txt" << endl ; }