-
Syntax Error
Code:
#include <stdio.h>
#include <stdlib.h>
#define WIDTH 10
#define HEIGHT 10
typedef struct SHIP
{
char ch;
unsigned length;
} SHIP;
typedef struct COORD
{
int x, y;
} COORD;
typedef struct NODE
{
SHIP *ship = NULL; // <-- Error here
int has_white_peg = 0, has_red_peg = 0;
} NODE;
typedef struct BOARD
{
NODE grid[WIDTH][HEIGHT];
} BOARD;
Code:
bship.c:20: warning: no semicolon at end of struct or union
bship.c:20: error: syntax error before ‘=’ token
bship.c:22: error: syntax error before ‘}’ token
bship.c:22: warning: type defaults to ‘int’ in declaration of ‘NODE’
bship.c:22: warning: data definition has no type or storage class
bship.c:26: error: syntax error before ‘NODE’
bship.c:26: warning: no semicolon at end of struct or union
bship.c:27: warning: type defaults to ‘int’ in declaration of ‘BOARD’
bship.c:27: warning: data definition has no type or storage class
bship.c:31: error: field ‘board’ has incomplete type
bship.c: In function ‘main’:
bship.c:39: error: type of formal parameter 1 is incomplete
bship.c:38: warning: unused variable ‘computer’
bship.c: At top level:
bship.c:43: error: parameter 1 (‘board’) has incomplete type
:confused: What am I missing?
-
You can't assign a value to a member of a structure inside the structure's definition.
You can initialize the structure where an instance of it is declared:
Code:
NODE instance = {NULL, 0};
Or you could just set that particular member afterwards:
Code:
NODE instance;
instance.ship = NULL;