Thread: parse error before "{" token

  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    11

    parse error before "{" token

    I have created a program

    Code:
    #include <stdio.h>
    int main()
    {
    struct cricket
    {
    char player_name[20];
    char team_name[20];
    float batting_average;
    }
    player[4];
    
    int i;
    
    player[0] = {"abcd","efg",67.87};
    player[1] = {"hijk","lmn",67.89};
    player[2] = {"opqr","stu",67.76};
    player[3] = {"vwxy","zzz",75.74};
    
    for(i=0;i<4;++i)
    printf("%s  %s  %f\n",player[i].player_name,player[i].team_name,player[i].batting_average);
    }
    but when compiling in cygwin with gcc, it gives
    parse error before "{" token

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,794
    you cannot initialize struct after declarartion
    use
    Code:
    struct cricket
    {
    char player_name[20];
    char team_name[20];
    float batting_average;
    }
    player[4] = {
    {"abcd","efg",67.87},
    {"hijk","lmn",67.89},
    {"opqr","stu",67.76},
    {"vwxy","zzz",75.74}
    };
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

  3. #3
    Registered User
    Join Date
    Dec 2006
    Posts
    11
    thx, i m just the beginner

  4. #4
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    and u forgot
    Code:
    return 0;
    ssharish2005

  5. #5
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,794
    Quote Originally Posted by ssharish2005
    and u forgot
    Code:
    return 0;
    ssharish2005
    this is optional for the main
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. Parsing and Tokens (strtok)
    By readerwhiz in forum C Programming
    Replies: 6
    Last Post: 04-22-2002, 09:57 AM