How do I replace a zero (0) with a blank space " " in array of struct in C++?

Viewed 28

I have three files. The struct to defined in the header file: The second file called functions, contains 2 function. A simple read from a text file fuction:

/*PersonCountVal is a value from another function that counts 
how many records there are in the txt file for the 'for loop'.*/

void PersonFileRead(int PersonCountVal, Person *PersonRecord) 
{
    ifstream PersonFile;
    PersonFile.open("person.txt");

    if (!PersonFile)
    {
        cerr << "File can't be opened or not found! " << endl;
        
        system("PAUSE");
        exit(1);
    }
    PersonFile.ignore(numeric_limits<streamsize>::max(), '\n'); 
    
//the value for PersonCountVal is 20 i.e there are 20 records in the text file
        for (int i = 0; i < PersonCountVal; i++) 
        {
            PersonFile >> 
            PersonRecord[i].name >> 
            PersonRecord[i].gender >> 
            PersonRecord[i].age >> 
        }
        PersonFile.close();


  }

The second function, the print funtion is:

    void PersonDetailPrint(int PersonCountVal , Person *PersonRecord)
    {
        for (int i = 0; i < PersonCountVal; i++) 
        {
            cout << PersonRecord[i].name << "\t";
            cout << PersonRecord[i].gender << "\t";
            cout << PersonRecord[i].age << "\t" << endl;
        }
        cout << "Total Records: " << PersonCountVal << endl;
    }

The third file , the main file, contains the call and other stuff.

Person PersonRec[PersonCount];

//Function 1 
PersonFileRead(PersonCount, pointerPersonRec);

//Function 2
PersonDetailPrint(PersonCount, pointerPersoRec);

Some of the data is in the text file is are zeros (0) i.e the person didn't provide an answer. How do I print a blank space " " instead of a zero in the output? Or any other value instead of zero like "N/A" or "No Response"?

The txt file may contain the following data.

Name Age Gender

John M 24

Jane F 0

Carl 0 0

Rory M 19

Marshall 0 21

I have posted some screenshots of what I mean below.

Screen output before

Screen output after

0 Answers
Related