lundi 24 octobre 2022

Get the two char values from the string pointer array

We have to write a function to a program that receives a pointer to a string array which we populated with a text file. We now have to get the year the person was born from their ID by not using any built in functions or using the brackets.

void displayYearsBorn(string *pointerArr, int num){
    cout << "List of years born" << endl << endl;

    char d1, d2, year;

    for (int i = 0; i < num; i++){
        if ((*(pointerArr + i) == '_')){
            d1 = (*(pointerArr + i + 1) - '0') * 10;
            d2 = (*(pointerArr + i + 1) - '0');

            cout << (*(pointerArr + i + 1) - '0') << endl;
        }
    }
}

The lecturer we have gave us the for loop as a hint but, it does not work. I just want to know if anybody would be able to help.

Aucun commentaire:

Enregistrer un commentaire