Question
C:UsersRaymondDesktop2401a2.c: In function 'initpiratearr': C:UsersRaymondDesktop2401a2.c:80:45: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types] piratearr->arr[piratearr->piratenum]=pirate; #include #include #include #include #define MAX_STR 32 #define MAX_ARR_SIZE 128 typedef struct{
C:\Users\Raymond\Desktop\2401a2.c: In function 'initpiratearr': C:\Users\Raymond\Desktop\2401a2.c:80:45: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types] piratearr->arr[piratearr->piratenum]=pirate;
#include
typedef struct{ char name[MAX_STR]; int strength; int armour; int health; }HeroType;
typedef struct{ int strength; int health; }PirateType;
typedef struct{ int piratenum; struct PirateType *arr[MAX_ARR_SIZE]; }ArrayType;
int randomInt(int); void initpiratearr(ArrayType*); void initpirate(PirateType*); void printresult(int,int,int,int);
int main(){ int timmywin=0; int haroldwin=0; int bothwin=0; int piratewin=0; HeroType *Timmy, *Harold; Timmy = (HeroType *)calloc(1,sizeof(HeroType)); Harold = (HeroType *)calloc(1,sizeof(HeroType)); strcpy(Timmy->name, "Timmy"); Timmy->strength =5; Timmy->armour=5; Timmy->health=30; strcpy(Harold->name, "Harold"); Harold->strength =7; Harold->armour=3; Harold->health=30;
ArrayType * try=(ArrayType*)calloc(1,sizeof(ArrayType)); for(int i=0;ihealth !=0 || Timmy->health !=0) && try->piratenum !=0){
// switch(struct HeroType Timmy && struct HeroType Harold){ // case(Timmy->health ==0 && try-> piratenum==0 && Harold->health !=0): // haroldwin+=1; // break; // case(Timmy->health !=0 && try-> piratenum==0 && Harold->health ==0): // timmywin+=1; // break; // case(Timmy->health !=0 && try-> piratenum==0 && Harold->health !=0): // bothwin+=1; // break; // case(Timmy->health ==0 && try-> piratenum!=0 && Harold->health ==0): // piratewin+=1; // break; // } }
} printresult(haroldwin,timmywin,piratewin,bothwin); return 0; }
void initpiratearr(ArrayType *piratearr){ piratearr->piratenum=0; while(piratearr->piratenumarr[piratearr->piratenum]=pirate; piratearr->piratenum++; }
}
void initpirate(PirateType *pirate){ srand(time(NULL)); pirate->health=20; pirate->strength=randomInt(3)+3; }
int randomInt(int max){ return(rand() % max); }
In C
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 structureStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started