A few problems I see. You are creating an array of 199 pointers to enemies, not 199 enemies.
Your for loop will not loop because i=0 to start and i==199 is false so loop is exited immediately.
Instead of explaining I will give the corrected code which works. Hope you will see why all the changes are made.
struct Enemy{
int hp;
int x;
int y;
}enemy[199];// actual enemies, not just pointers to them
void populate(Enemy* p_enemy)// pass a pointer to the array of enemies
{
for(int i=0; i<199; i++)// i<199 remains true for all desired iterations
{
p_enemy[i].hp = rand()%400;
p_enemy[i].x = rand()%1000;
p_enemy[i].y = rand()%1000;
}
}
int main(void)
{
populate(enemy);
for(int i=0; i<199; i++)
{
cout<<i<<endl;
cout<<enemy[i].hp<<endl;
cout<<enemy[i].x<<endl;
cout<<enemy[i].y<<endl<<endl;
}
cin.get();
return 0;
}
Actually, since you have declared the enemies array as global, it is visible to all functions. There is no need to pass anything to your populate(). You may hear from the anti-global-variable police here though.