I am trying to create an object (typedef struct) in C from multiple dyanimc arrays, but I'm having a few issues assigning values to the members, my code is below:
#define MAX_SHIPS 200
typedef struct enemy {
int enemyX[MAX_SHIPS];
int enemyY[MAX_SHIPS];
int enemyDistance[MAX_SHIPS];
int enemyHealth[MAX_SHIPS];
int enemyType[MAX_SHIPS];
}enemy;
^ define MAX_SHIPS and create the struct enemy.
number_of_friends = 0;
number_of_enemies = 0;
if (number_of_ships > 1)
{
for (i=1; i<number_of_ships; i++)
{
if (IsaFriend(i))
{
friendX[number_of_friends] = shipX[i];
friendY[number_of_friends] = shipY[i];
friendHealth[number_of_friends] = shipHealth[i];
friendFlag[number_of_friends] = shipFlag[i];
friendDistance[number_of_friends] = shipDistance[i];
friendType[number_of_friends] = shipType[i];
number_of_friends++;
}
else
{
int x;
for (x = 0; x < number_of_ships; x++)
{
enemy[x].enemyX = shipX[i];
enemy[x]. enemyY = shipY[i];
enemy[x].enemyDistance = shipDistance[i];
enemy[x].enemyHealth = shipHealth[i];
enemy[x].enemyType = shipType[i];
}
At the moment I get the error int x expected an identifier.
enemyX[number_of_enemies] = shipX[i];
enemyY[number_of_enemies] = shipY[i];
enemyHealth[number_of_enemies] = shipHealth[i];
enemyFlag[number_of_enemies] = shipFlag[i];
enemyDistance[number_of_enemies] = shipDistance[i];
enemyType[number_of_enemies] = shipType[i];
number_of_enemies++;
}
}
}
^ Code I want to remove / replace with the creation of the enemy struct.