Each time the program goes through a loop, nameField gets bigger and bigger. Strcat keeps adding new names to the field. How can I clear the field after each output? I thought it was something like nameField = {' '};...but that doesn't work. There has to be a simply way to clear everything from the nameField variable. I have spent way to much time trying to figure this out.

#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
using std::ifstream;

void outputLine(char, char);

int main()
    struct date
        short year;
        short month;
        short day;

    date aDate;

    struct president
        char lastName [15];
        char firstName [19];
        date heldOfficeBeg;
        date heldOfficeEnd;
        date birthDate;
        date deathDate;
        char birthState[3];
        char buriedState[3];
        char married;
        char politicalParty[5];

    president presRecord;
    char nameField[45];

    ifstream inPresFile("\\Users\\Owner\\Documents\\presfile.dat",ios::in);

    if (!inPresFile)
        cout<<"File could not be opened"<<endl;

    for (int counter=1; counter < 40; counter++)
        inPresFile.read(reinterpret_cast<char *> (&presRecord),sizeof (presRecord));

        strcat (nameField,presRecord.firstName);
        strcat (nameField," ");
        strcat (nameField,presRecord.lastName);


        //nameField = {' '};
        system ("pause");
8 Years
Discussion Span
Last Post by rickster11
Featured Replies
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.