The printName function here is supposed to print just the records with data, but instead prints all 100 records. Records are a struct char lastName[15], firstname[15], age[15]. Empty records are initialized to "unassigned', "", "0", respectively. Some comments represent ways I've tried to get it to work, but no luck. What's going wrong here?
Also, function update hangs after: cout << "Enter last and first name of account to update: ". That I'm still working on, but any clues there?
Thanks again.
Code:void update(const string& filename) { fstream personUpdate(filename.c_str()); string last, first; person id; cout << "Enter last and first name of account to update: "; cin >> last >> first; personUpdate.read((char *)&id, sizeof(person)); while (!personUpdate.eof()) { if (strcmp(id.lastName, last.c_str()) == 0 && strcmp(id.firstName, first.c_str()) == 0) { cout << "Enter new record (last name, first name, age): "; cin >> id.lastName >> id.firstName >> id.age; personUpdate.write((char*)&id, sizeof(person)); } } } void printName(const string& filename) { ifstream personPrint(filename.c_str()); person blank; int k = 1; // for(int k = 0; k < 100; k++) personPrint.read((char *)&blank, sizeof(person)); while (!personPrint.eof()) { // if (blank.lastName != "unassigned") // personPrint.seekg(k * sizeof(person)); // personPrint.read((char *)&blank, sizeof(person)); if (blank.age != "0 ") cout << k << ": " << blank.lastName << " "<< blank.firstName << " "<< blank.age << endl; personPrint.read((char *)&blank, sizeof(person)); k++; } }



LinkBack URL
About LinkBacks



