You have a couple of problems.
First, arrays are 0 based. That means that the first element is 0
, and the last one (in your case) is 19
. There is no 20
. Consequently, referring to food[20]
is undefined behavior, which allows your program to do literally anything, although the most likely is probably your program crashing.
The second problem with your code is that std::fill_n()
looks for the first object you want filled, not the last. That means, you want food[0]
, not food[20]
:
fill_n(food[0].qtyData, 20, 0);
fill_n(food[0].priceOrder, 20, 0.00);
fill_n(food[0].nameOrder, 20, "");
Something like that should work, although--full disclosure--it is untested. But it should be in the general ballpark of what you need.
The only other thing that I see that could be a problem is by calling something like food[0].qtyData
, std::fill_n()
may not work like you would think it would, since qtyData
is an int
. I'm not familiar enough with std::fill_n()
, but I think it might only clear the next 20 int
s, not the next 20 qtyData
s. You may need the full struct like this instead:
fill_n(food[0], 20, 0);
Although, again, this is still untested.