Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing an array of bitfields to a function

  • Thread starter Thread starter -
  • Start date Start date
Status
Not open for further replies.

Guest
Hi,

I was trying to think of a good way to create a battleship game using an array of bitfields, where each point could be 1 byte and would hold all the infomation I need. My program looks like this, but will not compile. Can anyone tell me if what i'm trying to do is impossible/stupid/possible with correct syntax. Thanks.

#include
using namespace std;

struct status {
bool ship :1;
bool shot :1;
};

void init(status *coords);

int main()
{
status coords[10][10];

init(coords);

//test for correct output
cout << coords[0][0].shot << ' ' << coords[0][1].shot;

return 0;
}

void init(status *coords) {
int i, j;
for(i=0; i<10; i++)
for(j=0; j<10; j++) {
coords[j].ship = false;
coords[j].shot = false;
}
}

 
Hi,
try to declare the parameter of init function with **coords, since it is a 2D array.

cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top