It is very easy: you must count how many fields are already used and than stop the ship making. You must also check that the ship isnt going out of the playground. At best is to check that the starting point provides enough space and else move it correctly.
Use a fix playground array as global instance like a chess board:
char playground[60][60] = {0};
a horizontal ship:
int startx = 50;int starty = 10;if( startx + 5 > 60 ) {
startx = 60 - 5;
}
for(int i = 0; i < 5; i++ ) {
playground[startx+i][starty] = 1; }
If you write a function around it, you can make the "5" has input param to build other ships.