Thread: Expression Syntax Error in Turbo C

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    1

    Expression Syntax Error in Turbo C

    Hi there,

    I am a novice programmer and have chosen C to begin with. This is a really really simple code where I am trying to change the fields of of an extern structure. When I compile it with turbo C. I get expression syntax error from the compiler on the only line of code.

    Following is the small piece of C code
    /*=================================*/
    Code:
    #include<stdio.h>
    
    struct {
        int status[2];
        float time[2];
        float state[4][2];
    } states = {{0,0},{0,0},{{1,2},{3,4},{5,6},{7,8}}};
    
    void main(void)
    {
    
    states.status = {1,1};
    
    }
    /*=================================*/

    I will really appreciate any kind of help.

    Thanking you in anticipation.

    Regards,
    Vivek.

  2. #2
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    1. Never use void main.
    2.Turbo C is a fossil. If you've just started learning C, try your hands on some other compiler.
    3. "status" is an array, so you should use array subscripting to do anything with it. So the line
    Code:
    states.status = {1,1};
    needs array subscripting. After subscripting it, only one value can be assigned to it.
    [edit]
    By the way, you can see the FAQ for void main
    [/edit]
    Last edited by BEN10; 06-29-2009 at 10:30 PM.
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by BEN10 View Post
    3. "status" is an array, so you should use array subscripting to do anything with it. So the line
    Code:
    states.status = {1,1};
    needs array subscripting. After subscripting it, only one value can be assigned to it.
    What does that mean exactly?
    And re arrays:
    Arrays can be initialized the way you do, but never assigned that way.
    Initialized is when they are first created; afterwards it's all assignment.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    I knew that I'll be misunderstood. I didn't know how to tell that but this is what I meant.
    For assigning both the array elements a 1 he should have done this
    Code:
    states.status[0] = 1;
    states.status[1]=1;
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 08:26 AM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM