how to reset an array

This is function within a loop in the main. The loop may use the function several times. I would like it to reset the arrays names and numbers prior to running the while loop in this function, but I am not sure how to do that. Is there a way to send it as a parameter that resets it. Any ideas?





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

void get_info(ifstream &fin, string names[], string numbers[], int& count) 
{
     string next;
     open_in (fin);
     while (! fin.eof())
     {
           getline (fin, names [count]);
           getline (fin, numbers [count]);
           count++;
           
     }
     count--;
     
     fin.clear();
     fin.close();
}
Last edited on
There is no need to reset arrays because each element will be overwritten. Also it is not clear what initial value shall be assigned to the elements. Let assume that names and numbers shall be empty, then you can use standard algorithm std::fill_n (or std::fill) to reset your arrays. But the problem is that you do not pass to your function the sizes of the arrays. I think you shall to change your function such a way that parameter count would contain size of the arrays.

Topic archived. No new replies allowed.