12/06/2020, 22:29

C language.

Em bị lỗi syntax em sửa mãi không đc. Mong anh chị giúp đỡ em

#include <stdio.h>
#include <stdlib.h>
//#include "bship.h"
 
#define ROWS 7
#define COLUMNS 10
 
// The number of different ship types
#define FLEETSIZE 3
typedef struct {
int length;
char name[20];
} Ship;
void placeShip(int board[ROWS][COLUMNS], Ship ships[FLEETSIZE])
{
int i , x,y, shipType;
char orientation;
int j;
int overlap = 0;
int temp_board[ROWS][COLUMNS];
for(int r = 0; r < ROWS; r++)
for(int c =0; c < COLUMNS; c++)
temp_board[r][c] = board[r][c];
for(i = 0; i < FLEETSIZE; i++)
{
printf("Enter ship type: ");
scanf("%d", &shipType);
printf("Enter x and y value: ");
scanf("%d %d", &x, &y);
printf("\nEnter the orientation: ");
scanf("%c", &orientation);
printf("\nEnter the orientation: ");
 
//check for *
if(ask_input(ships, shipType, orientation, x,y) == 0)
{
break;
}
//check oversize
if(orientation == 'V')
{
if (y+ ships[shipType] >= ROWS )
{
msg_place_failure();
i--;
continue;
}
else
{
//check overlap
for(j = y; j < y+ships[shipType]; j++)
{
if(temp_board[x][j] != 0)
{
msg_place_failure();
overlap = 1;
}
temp_board[i][j] = 1;
}
}
}
 
else
{
if (y+ ships[shipType] >= COLUMNS )
{
msg_place_failure();
i--;
continue;
}
else
{
for(j = y; j < y+ships[shipType]; j++)
{
if(temp_board[x][j] != 0)
{
msg_place_failure();
overlap = 1;
}
temp_board[i][j] = 1;
 
}
}
}
msg_place_success();
board = temp_board;
}
}
int detectHit(int board[ROWS][COLUMNS])
{
int x,y;
printf("Enter coordinate(x,y) to shoot:");
scanf("%d %d", &x, &y);
while(x!='*' && y!='*'){
 
for(int i = 0; i < ROWS; i++)
for(int j = 0; j < COLUMNS; j++){
if(board[i][j] == 1){
ask_shot(x,y);
if(board[x][y]==1){
msg_hit_success();
board[x][y] = 0;
if(board[x+2][y+1] == 0 && board[x+1][y+2] == 0
&& board[x][y+1] == 0 && board[x+1][y] == 0)
msg_ship_destroyed();
}else{
msg_hit_failure();
}
}
}
}
if(x=='*' || y =='*')
return 0;
else
return 1;
}
int main(){
//create an array with the different ships
Ship fleet[FLEETSIZE];
// Initialize the ships in the array
// by reading from 'ship.txt'
initialize_ship(fleet);
int hitCount = 0;
int board[ROWS][COLUMNS];
//initialize board to 0
for(int i = 0; i < ROWS; i++)
for(int j =0; j < COLUMNS; j++)
board[i][j] = 0;
placeShip(board,fleet);
detectHit(board);
}
em bị lỗi invalid operand to binary+ ('int' and 'Ship')
và bị lỗi too few arguments to function.
Mong anh chị giúp đỡ em ạ!!!
 
0