I am having trouble with structures in a battleship project. The instructor gave us a header file with all of the function prototypes we have to use and I am having trouble with the first one, "initialize". In the header file we have to use, the instructor has this:
//
// data structures definitions
//
constint FLEET_SIZE=5; // number of battleships
constint FIELD_SIZE=5; // the field (ocean) is FIELD_SIZExFIELD_SIZE
// coordinates (location) of the ship and shots
struct location{
int x; // 1 through FIELD_SIZE
char y; // 'a' through FIELD_SIZE
};
// contains ship's coordinates (location) and whether is was sunk
struct ship{
location loc;
bool sunk;
};
//
// initialization functions
//
void initialize(ship[]); // places all ships in -1 X location to signify
// that the ship is not deployed
location pick(void); // generates a random location
bool match(ship, location); // returns true if this location matches
// the location of the ship
// returns false otherwise
int check(const ship[], location); // returns the index of the element
// of the ship[] array that matches
// location. Returns -1 if none match
// uses match()
void deploy(ship[]); // places an array of battleships in
// random locations in the ocean
I am starting with the initialize function in the main function and am wondering what exactly is going on. So the function Initialize takes the structure ship which as an array size of the a new variable (the number of ships deployed) right? So is this where we initialize all 5 of the ships to have a value of -1? In the main function, when i do something like this:
1 2 3 4 5
int main(){
initialize(ship);
}
it doesn't compile. So then I tried this:
1 2 3 4 5 6 7
int main(){
ship s;
initialize(s);
}
and it still didn't compile. I am wondering how I can pass the structure in a function if these ways I have tried don't work.
Okay that makes much more sense, thank you. Now when I try to make this function I am getting an error saying (Error: expected an identifier) Here is my code: