Thread: Syntax Error

  1. #1
    Registered User MacNilly's Avatar
    Join Date
    Oct 2005
    Location
    CA, USA
    Posts
    466

    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
    What am I missing?

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    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;
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM
  5. Linking error
    By DockyD in forum C++ Programming
    Replies: 10
    Last Post: 01-20-2003, 05:27 AM