Question: Assignment2.c: In function initpiratearr: Assignment2.c:52:51: error: incompatible types when assigning to type struct PirateType * from type struct PirateType piratearr->piratearr[piratearr->piratenum]=initpirate(); Assignment2.c #include #include #include #include

Assignment2.c: In function initpiratearr:

Assignment2.c:52:51: error: incompatible types when assigning to type struct PirateType * from type struct PirateType piratearr->piratearr[piratearr->piratenum]=initpirate();

Assignment2.c

#include #include #include #include

#define MAX_STR 32

#define MAX_ARR_SIZE 128 struct HeroType{ char name[MAX_STR]; int strength; int armour; int health; }; struct PirateType{ int strength; int health; }; typedef struct{ int piratenum; struct PirateType *piratearr[MAX_ARR_SIZE]; }ArrayType; int randomInt(int); void initpiratearr(ArrayType*); struct PirateType initpirate(); int main(){ struct HeroType Timmy; strcpy(Timmy.name, "Timmy"); Timmy.strength =5; Timmy.armour=5; Timmy.health=30; struct HeroType Harold; strcpy(Harold.name, "Harold"); Harold.strength =7; Harold.armour=3; Harold.health=30; for(int i=0;ipiratenum=0; while(piratearr->piratenumpiratearr[piratearr->piratenum]=initpirate(); piratearr->piratenum++; } } struct PirateType initpirate(){ srand(time(NULL)); struct PirateType pirate; pirate.health=20; pirate.strength=randomInt(3)+3; return pirate; } int randomInt(int max){ return(rand() % max); }

Assignment2.c: In function initpiratearr: Assignment2.c:52:51: error: incompatible types when assigning to type

In C I am trying to initialize the ArrayType and give the piratearr 10 pirate by dynamic allocate by i am not sure what to do to fix that bug

Your program will define the following data types as structures the HeroType structure will contain a hero's name (as a string), as well as indicators of his strength, his armour, and his health, all represented as integers the PirateType structure will contain a pirate's strength and health indicators the ArrayType structure will be a collection structure which contains a primitive (regular) array of PirateType pointers; the ArrayType will also need to store the current number of pirates in the array Your program will initialize one HeroType structure for Timmy, and another one for Harold, as follows Timmy's strength is set at 5, his armour at 5, and his health indicator begins at 30 points Harold's strength is set at 7, his armour at 3, and his health indicator begins at 30 points For each run of the simulation, a different ArrayType structure will be initialized to hold the pirates: the array structure will be filled with 10 dynamically allocated PirateType structures .each pirate will have a strength as a randomly generated number between 3 and 6 (inclusively) .each pirate will have a health indicator that begins at 20 points .each pirate will be pushed to the back (the end) of the ArrayType structure

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!