Im making a game about gathering elements from exoplanets. I would have no problem if i could do this all in one function but Im passing the pointer of an array of structs to multiple functions. So I keep getting errors because i dont know how many pointers to put the parameter and argument of each function. especially the function within a function (called missionMenu()) is a real headache to work with. Im also probably messing up the pointers in the function earth() too.. Any help would be greatly appreciated!
EDIT: I need help fixing the scanf in the missionMenu() function and i think misuse of pointers i mentioned above have something to do with it
#include <stdio.h>
#include <stdlib.h>
#define pause system("pause")
#define cls system("cls")
#define flush fflush(stdin)
#define SIZE 1000
main(){
int count=0;
ELEMENT* element[SIZE];
earth(&count,element);
}//End main
void earth(int *c,ELEMENT **element){
int userMenuChoice = 0;
int i;
int number;
displayMenu();
element[*c] = malloc(sizeof(ELEMENT));
scanf("%i", &userMenuChoice);
switch (userMenuChoice) {
case 1:
missionMenu(element[*c],*c);
break;
case 2:
for(i=0;i<*c;i++)
printf("\t%i\t%i\n", element[i]->hydrogen);
break;
case 3:
break;
}while(userMenuChoice != 4);
}//end end
void missionMenu(ELEMENT *element, int c ){
int missionChoice;
cls;
printf("Which planet would you like to escapade/exploit? \n\n");
printf("1. Gliese 436 b \n");
printf("2. Oxygen Planet\n");
printf("3. 55 Cancri E\n");
printf("4. Nitrogen \n");
printf("Please input your choice (1-3): \n\n");
missionChoice = 0;
scanf("%i", &missionChoice);
switch (missionChoice) {
case 1:
cls;
printf("\n\n\nWelcome to Planet Gliece 436 b, a planet made of burning ice.\n");
printf("The extreme gravity of this planet forces the water to stay in solid form,\neven though the temperature is over 570° fahrenheit.\n\n");
pause;
printf("\n\n\tHow much Hydrogen would you like to collect?");
//scanf("%i",&collect);
scanf("%[^\n]s", element->hydrogen); flush;
printf("\n\ntHow much Oxygen would you like to collect?");
// scanf("%i",&collect);
scanf("%[^\n]s", element->oxygen); flush;
c=c+1;
break;
case 2:
break;
case 3:
break;
case 4:
break;
}while(missionChoice != 5);
}//end mission menu
ELEMENT** newElement() {
ELEMENT** element;
element = malloc(sizeof(ELEMENT));
return element;
} //end newTeam
In your main
you try to call the earth
function with a pointer to an ELEMENT, your array. If you check the definition of earth(...)
, you see that it accepts a pointer to a pointer to an ELEMENT, which is not what you're passing it.