parse error before "{" token

This is a discussion on parse error before "{" token within the C Programming forums, part of the General Programming Boards category; I have created a program Code: #include <stdio.h> int main() { struct cricket { char player_name[20]; char team_name[20]; float batting_average; ...

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    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}
    };
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  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,682
    and u forgot
    Code:
    return 0;
    ssharish2005

  5. #5
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Quote Originally Posted by ssharish2005
    and u forgot
    Code:
    return 0;
    ssharish2005
    this is optional for the main
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

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, 09: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21